-
Notifications
You must be signed in to change notification settings - Fork 3
/
config_test.go
79 lines (76 loc) · 1.29 KB
/
config_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 main
import "testing"
func TestReplaceNames(t *testing.T) {
cases := []struct {
name string
path string
params map[string]int
want []string
}{
{
"const1",
"/simple?v=%(c1)%",
map[string]int{},
[]string{"/simple?v=hoge"},
},
{
"vars1",
"/simple?v=%(v1)%",
map[string]int{},
[]string{"/simple?v=v1_0001", "/simple?v=v1_0002"},
},
{
"exvars1",
"/simple?v=%(ev1)%",
map[string]int{},
[]string{"/simple?v=10001"},
},
{
"non vars",
"/simple",
map[string]int{},
[]string{"/simple"},
},
{
"empty expand vars",
"/simple?v=%()%",
map[string]int{},
[]string{"/simple?v=%()%"},
},
{
"non expand vars",
"/simple?vvv=%(dummyvalue)%",
map[string]int{},
[]string{"/simple?vvv=%(dummyvalue)%"},
},
{
"empty path",
"",
map[string]int{},
[]string{""},
},
{
"blank",
" ",
map[string]int{},
[]string{" "},
},
}
config := Config{}
if err := config.Load("example/vars.yml"); err != nil {
t.Fatal("fail config loading")
}
for _, tt := range cases {
ret := ReplaceNames(tt.path, map[string]int{})
ok := false
for _, w := range tt.want {
if ret == w {
ok = true
break
}
}
if !ok {
t.Fatalf("%s invalid result: want=%s, ret=%s", tt.name, tt.want, ret)
}
}
}