-
Notifications
You must be signed in to change notification settings - Fork 4
/
subnet_test.go
42 lines (34 loc) · 704 Bytes
/
subnet_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
package vpcinfo
import (
"net"
"testing"
)
var (
testSubnets Subnets
)
func init() {
testSubnets = make(Subnets, len(testTXT))
for i, s := range testTXT {
if err := parse(s, &testSubnets[i]); err != nil {
panic(err)
}
}
}
func TestSubnets(t *testing.T) {
for _, s := range testSubnets {
ip := make(net.IP, len(s.CIDR.IP))
copy(ip, s.CIDR.IP)
ip[len(ip)-1] = 1
if x := testSubnets.LookupAddr(&net.TCPAddr{IP: ip, Port: 4242}); x != s {
t.Error("subnet mismatch for", ip)
t.Log("expected:", s)
t.Log("found: ", x)
}
}
}
func BenchmarkSubnetsZoneOf(b *testing.B) {
ip := net.ParseIP("10.31.32.33")
for i := 0; i < b.N; i++ {
_ = testSubnets.LookupIP(ip)
}
}