-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathip4_test.go
57 lines (48 loc) · 899 Bytes
/
ip4_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
package iana
import (
"path"
"runtime"
"testing"
"github.com/rspamd/goasn/log"
)
var (
expectedEntries = []string{
"127.0.0.1/32",
"127.0.0.0/24",
"10.1.0.0/16",
"10.0.0.0/8",
"255.255.255.255/32",
}
unexpectedEntries = []string{
"1.1.1.1/32",
"8.8.8.0/24",
"223.0.0.1/24",
}
)
func TestIANAIP4(t *testing.T) {
log.SetupLogger(false)
_, ourFile, _, _ := runtime.Caller(0)
testDataDir := path.Join(path.Dir(ourFile), "testdata")
tree, err := GetReservedIP4(testDataDir)
if err != nil {
t.Fatal(err)
}
for _, e := range expectedEntries {
inf, err := tree.FindCIDR(e)
if err != nil {
t.Fatal(err)
}
if inf == nil {
t.Fatalf("didn't find expected entry %s", e)
}
}
for _, e := range unexpectedEntries {
inf, err := tree.FindCIDR(e)
if err != nil {
t.Fatal(err)
}
if inf != nil {
t.Fatalf("found unexpected entry %s", e)
}
}
}