-
Notifications
You must be signed in to change notification settings - Fork 13
/
httpunit_test.go
53 lines (51 loc) · 1000 Bytes
/
httpunit_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
package httpunit
import "testing"
func TestIPMapResolve(t *testing.T) {
m := IPMap{
"BASEIP": []string{"87.65.43."},
`^(\d+)$`: []string{"*", "BASEIP$1", "BASEIP($1+64)", "123.45.67.$1"},
`^(\d+)i$`: []string{"*", "10.0.1.$1", "10.0.2.$1", "BASEIP$1", "BASEIP($1+64)", "123.45.67.$1"},
}
tests := []struct {
in string
error bool
out []string
}{
{
"16",
false,
[]string{
"*",
"123.45.67.16",
"87.65.43.16",
"87.65.43.80",
},
},
{
"16i",
false,
[]string{"*",
"10.0.1.16",
"10.0.2.16",
"123.45.67.16",
"87.65.43.16",
"87.65.43.80",
},
},
{
"unused",
true,
nil,
},
}
for i, test := range tests {
ips, err := m.Expand(test.in)
if err != nil && !test.error {
t.Errorf("%v: expected no error, got %v", i, err)
} else if err == nil && test.error {
t.Errorf("%v: expected error", i)
} else if !strEqual(ips, test.out) {
t.Errorf("%v: expected %v, got %v", i, test.out, ips)
}
}
}