-
Notifications
You must be signed in to change notification settings - Fork 6
/
net_test.go
76 lines (70 loc) · 1.63 KB
/
net_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
package fasttld
import "testing"
type looksLikeIPAddressTest struct {
maybeIPAddress string
isIPAddress bool
}
var looksLikeIPv4AddressTests = []looksLikeIPAddressTest{
{maybeIPAddress: "",
isIPAddress: false,
},
{maybeIPAddress: " ",
isIPAddress: false,
},
{maybeIPAddress: "google.com",
isIPAddress: false,
},
{maybeIPAddress: "1google.com",
isIPAddress: false,
},
{maybeIPAddress: "127.0.0.1",
isIPAddress: true,
},
{maybeIPAddress: "127.0.0.256",
isIPAddress: false,
},
}
var looksLikeIPv6AddressTests = []looksLikeIPAddressTest{
{maybeIPAddress: "",
isIPAddress: false,
},
{maybeIPAddress: " ",
isIPAddress: false,
},
{maybeIPAddress: "google.com",
isIPAddress: false,
},
{maybeIPAddress: "1google.com",
isIPAddress: false,
},
{maybeIPAddress: "aBcD:ef01:2345:6789:aBcD:ef01:2345:6789",
isIPAddress: true,
},
{maybeIPAddress: "gGgG:ef01:2345:6789:aBcD:ef01:2345:6789",
isIPAddress: false,
},
{maybeIPAddress: "aBcD:ef01:2345:6789:aBcD:ef01:127.0.0.1",
isIPAddress: true,
},
{maybeIPAddress: "aBcD:ef01:2345:6789:aBcD:ef01:127.0.0.256",
isIPAddress: false,
},
}
func TestIsIPv4(t *testing.T) {
for _, test := range looksLikeIPv4AddressTests {
isIPv4Address := isIPv4(test.maybeIPAddress)
if isIPv4Address != test.isIPAddress {
t.Errorf("Output %t not equal to expected %t",
isIPv4Address, test.isIPAddress)
}
}
}
func TestIsIPv6(t *testing.T) {
for _, test := range looksLikeIPv6AddressTests {
isIPv6Address := isIPv6(test.maybeIPAddress)
if isIPv6Address != test.isIPAddress {
t.Errorf("Output %t not equal to expected %t",
isIPv6Address, test.isIPAddress)
}
}
}