-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrdap-ip-network_test.go
79 lines (62 loc) · 1.6 KB
/
rdap-ip-network_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package adapters
import (
"context"
"testing"
"github.com/openrdap/rdap"
"github.com/overmindtech/cli/sdpcache"
)
func TestIpNetworkAdapterSearch(t *testing.T) {
t.Parallel()
src := &RdapIPNetworkAdapter{
ClientFac: func() *rdap.Client { return testRdapClient(t) },
Cache: sdpcache.NewCache(),
IPCache: NewIPCache[*rdap.IPNetwork](),
}
items, err := src.Search(context.Background(), "global", "1.1.1.1", false)
if err != nil {
t.Fatal(err)
}
if len(items) != 1 {
t.Fatalf("Expected 1 item, got %v", len(items))
}
item := items[0]
if item.UniqueAttributeValue() != "1.1.1.0 - 1.1.1.255" {
t.Errorf("Expected unique attribute value to be 1.1.1.0 - 1.1.1.0 - 1.1.1.255, got %v", item.UniqueAttributeValue())
}
if len(item.GetLinkedItemQueries()) != 3 {
t.Errorf("Expected 3 linked items, got %v", len(item.GetLinkedItemQueries()))
}
// Then run a get for that same thing and hit the cache
_, err = src.Get(context.Background(), "global", item.UniqueAttributeValue(), false)
if err != nil {
t.Fatal(err)
}
}
func TestCalculateNetwork(t *testing.T) {
t.Parallel()
tests := []struct {
Start string
End string
Expected string
}{
{
Start: "10.0.0.0",
End: "10.0.0.255",
Expected: "10.0.0.0/24",
},
{
Start: "10.0.0.0",
End: "10.0.0.7",
Expected: "10.0.0.0/29",
},
}
for _, test := range tests {
network, err := calculateNetwork(test.Start, test.End)
if err != nil {
t.Fatal(err)
}
if network.String() != test.Expected {
t.Errorf("Expected network to be %v, got %v", test.Expected, network.String())
}
}
}