-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils_test.go
79 lines (73 loc) · 1.41 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package postmaster
import (
"testing"
)
func TestMakeUrl(t *testing.T) {
pm := New("key")
if pm.makeUrl("v", "endp") != "https://api.postmaster.io/v/endp" {
t.Error("wrong url for default BaseUrl")
}
pm.SetBaseUrl("something")
if pm.makeUrl("v", "endp") != "something/v/endp" {
t.Error("wrong url for custom BaseUrl")
}
}
func TestUrlencode(t *testing.T) {
m := make(map[string]string)
m["some"] = "thing"
if urlencode(m) != "&some=thing&" {
t.Error("failed for 1 param")
}
m["any"] = "one"
if urlencode(m) != "&some=thing&any=one&" {
t.Error("failed for 2 params")
}
m["blank"] = ""
if urlencode(m) != "&some=thing&any=one&" {
t.Error("failed for blank param")
}
}
type N struct {
A string
B int
C float32
}
type S struct {
A string
B int
C float32
D *N
}
func TestMapStruct(t *testing.T) {
var m map[string]string
s := new(S)
m = mapStructNested(s, "")
if len(m) != 0 {
t.Error("non-empty map for empty struct")
}
s.A = "test"
s.B = 5
s.C = 3.2
m = mapStructNested(s, "")
if len(m) != 3 {
t.Error("map should contain exactly 3 items")
}
if m["a"] != "test" {
t.Error("wrong value for A")
}
if m["b"] != "5" {
t.Error("wrong value for B")
}
if m["c"] != "3.2" {
t.Error("wrong value for C")
}
s.D = new(N)
s.D.B = 5
m = mapStructNested(s, "")
if len(m) != 4 {
t.Error("map should contain exactly 4 items")
}
if m["d[b]"] != "5" {
t.Error("wrong value for D.B")
}
}