-
Notifications
You must be signed in to change notification settings - Fork 18
/
httprate_test.go
59 lines (57 loc) · 1.02 KB
/
httprate_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
package httprate
import "testing"
func Test_canonicalizeIP(t *testing.T) {
tests := []struct {
name string
ip string
want string
}{
{
name: "IPv4 unchanged",
ip: "1.2.3.4",
want: "1.2.3.4",
},
{
name: "bad IP unchanged",
ip: "not an IP",
want: "not an IP",
},
{
name: "bad IPv6 unchanged",
ip: "not:an:IP",
want: "not:an:IP",
},
{
name: "empty string unchanged",
ip: "",
want: "",
},
{
name: "IPv6 test 1",
ip: "2001:DB8::21f:5bff:febf:ce22:8a2e",
want: "2001:db8:0:21f::",
},
{
name: "IPv6 test 2",
ip: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
want: "2001:db8:85a3::",
},
{
name: "IPv6 test 3",
ip: "fe80::1ff:fe23:4567:890a",
want: "fe80::",
},
{
name: "IPv6 test 4",
ip: "f:f:f:f:f:f:f:f",
want: "f:f:f:f::",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := canonicalizeIP(tt.ip); got != tt.want {
t.Errorf("canonicalizeIP() = %v, want %v", got, tt.want)
}
})
}
}