forked from msgboxio/ike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet_test.go
44 lines (36 loc) · 999 Bytes
/
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
package ike
import (
"net"
"testing"
)
func TestNetIPNetToFirstLastAddress(t *testing.T) {
_, n, _ := net.ParseCIDR("198.51.100.1/32")
f, l, _ := IPNetToFirstLastAddress(n)
if f.String() != "198.51.100.1" {
t.Fail()
}
if l.String() != "198.51.100.1" {
t.Fail()
}
}
func TestNetFirstLastAddressToIPNet1(t *testing.T) {
first := net.ParseIP("198.51.100.0")
last := net.ParseIP("198.51.100.255")
if out := FirstLastAddressToIPNet(first, last); out.String() != "198.51.100.0/24" {
t.Errorf("%s", out)
}
}
func TestNetFirstLastAddressToIPNet2(t *testing.T) {
first := net.ParseIP("198.51.100.1")
last := net.ParseIP("198.51.100.1")
if out := FirstLastAddressToIPNet(first, last); out.String() != "198.51.100.1/32" {
t.Errorf("%s", out)
}
}
func TestNetFirstLastAddressToIPNet3(t *testing.T) {
first := net.ParseIP("0.0.0.0")
last := net.ParseIP("255.255.255.255")
if out := FirstLastAddressToIPNet(first, last); out.String() != "0.0.0.0/0" {
t.Errorf("%s", out)
}
}