-
Notifications
You must be signed in to change notification settings - Fork 2
/
net_test.go
46 lines (43 loc) · 1.26 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
package utils
import (
"net"
"testing"
)
func TestNtoI(t *testing.T) {
var ipInt uint32
ipInt = NtoI(net.ParseIP("0.0.0.0"))
if ipInt != uint32(0) {
t.Errorf("Invalid value %d for ip 0.0.0.0, Expected 0", ipInt)
}
ipInt = NtoI(net.ParseIP("0.0.0.1"))
if ipInt != uint32(1) {
t.Errorf("Invalid value %d for ip 0.0.0.1, Expected 1", ipInt)
}
ipInt = NtoI(net.ParseIP("128.0.0.0"))
if ipInt != uint32(2147483648) {
t.Errorf("Invalid value %d for ip 128.0.0.0, Expected 2147483648", ipInt)
}
ipInt = NtoI(net.ParseIP("255.255.255.255"))
if ipInt != uint32(4294967295) {
t.Errorf("Invalid value %d for ip 255.255.255.255, Expected 4294967295", ipInt)
}
}
func TestItoN(t *testing.T) {
var ip net.IP
ip = ItoN(uint32(0))
if ip.String() != "0.0.0.0" {
t.Errorf("Invalid ip %s for uint32(0). Expected 0.0.0.0", ip.String())
}
ip = ItoN(uint32(1))
if ip.String() != "0.0.0.1" {
t.Errorf("Invalid ip %s for uint32(1). Expected 0.0.0.1", ip.String())
}
ip = ItoN(uint32(2147483648))
if ip.String() != "128.0.0.0" {
t.Errorf("Invalid ip %s for uint32(2147483648). Expected 128.0.0.0", ip.String())
}
ip = ItoN(uint32(4294967295))
if ip.String() != "255.255.255.255" {
t.Errorf("Invalid ip %s for uint32(4294967295). Expected 255.255.255.255", ip.String())
}
}