-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathv4util_test.go
More file actions
56 lines (43 loc) · 866 Bytes
/
v4util_test.go
File metadata and controls
56 lines (43 loc) · 866 Bytes
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
package netutil
import (
"net"
"testing"
)
func TestIP4ToInt(t *testing.T) {
t.Parallel()
if IP4ToInt(net.ParseIP("0.0.1.0")) != 256 {
t.Error(`0.0.1.0 != 256`)
}
if IP4ToInt(net.ParseIP("0.0.1.1")) != 257 {
t.Error(`0.0.1.0 != 257`)
}
}
func TestIntToIP4(t *testing.T) {
t.Parallel()
if !IntToIP4(256).Equal(net.ParseIP("0.0.1.0")) {
t.Error(`256 != 0.0.1.0`)
}
if !IntToIP4(257).Equal(net.ParseIP("0.0.1.1")) {
t.Error(`257 != 0.0.1.0`)
}
}
func TestHostsFunc(t *testing.T) {
t.Parallel()
_, n, err := net.ParseCIDR("12.34.56.0/30")
if err != nil {
t.Fatal(err)
}
f, err := HostsFunc(n)
if err != nil {
t.Fatal(err)
}
if !f().Equal(net.ParseIP("12.34.56.1")) {
t.Error("f() != 12.34.56.1")
}
if !f().Equal(net.ParseIP("12.34.56.2")) {
t.Error("f() != 12.34.56.2")
}
if f() != nil {
t.Error("f() != nil")
}
}