-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_test.go
105 lines (97 loc) · 2.39 KB
/
map_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package asndb
import (
"reflect"
"testing"
)
func TestASNMap_Integration(t *testing.T) {
type wantASList struct {
asn int
wantCount int
wantFound bool
}
tests := []struct {
name string
asList []AS
wantASNLen int
wantListASN []AS
wantASList []wantASList
}{
{
name: "test1",
asList: []AS{
{
ASNumber: 4,
ASDescription: "the 4th asn",
},
{ASNumber: 1},
{
ASNumber: 0,
ASDescription: "the 0th asn",
CountryCode: "nil",
},
{ASNumber: 3}, {ASNumber: 2}, {ASNumber: 2}, {ASNumber: 2},
},
wantASNLen: 5,
wantListASN: []AS{
{
ASNumber: 0,
ASDescription: "the 0th asn",
CountryCode: "nil",
},
{ASNumber: 1}, {ASNumber: 2}, {ASNumber: 3},
{
ASNumber: 4,
ASDescription: "the 4th asn",
},
},
wantASList: []wantASList{
{asn: -1, wantFound: false},
{asn: 0, wantCount: 1, wantFound: true},
{asn: 1, wantCount: 1, wantFound: true},
{asn: 2, wantCount: 3, wantFound: true},
{asn: 3, wantCount: 1, wantFound: true},
{asn: 4, wantCount: 1, wantFound: true},
{asn: 5, wantFound: false},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := NewASNMap(tt.asList)
if gotASNLen := len(m.m); gotASNLen != tt.wantASNLen {
t.Errorf("ASNMap.m len() = %v, want %v", gotASNLen, tt.wantASNLen)
}
if gotListASN := m.ListASN(); !reflect.DeepEqual(gotListASN, tt.wantListASN) {
t.Errorf("ASNMap.ListASN() = %v, want %v", gotListASN, tt.wantListASN)
}
l := m.ListASN()
for i, as := range tt.wantListASN {
if l[i] != as {
t.Errorf("ASN.ListASN()[%d] = %v, want %v", i, l[i].ASNumber, as.ASNumber)
}
}
for _, tx := range tt.wantASList {
gotASNs, gotFound := m.ListAS(tx.asn)
if gotFound != tx.wantFound {
t.Errorf("ASN.ASList() found = %v, want %v", gotFound, tx.wantFound)
}
if tx.wantFound == false {
continue
}
if len(gotASNs) != tx.wantCount {
t.Errorf("ASN.ASList() count = %v, want %v", gotASNs, tx.wantCount)
}
}
if asl, found := m.ListAS(0); found {
asl[0].ASNumber = 1
if asl2, found2 := m.ListAS(0); found2 {
if asl2[0].ASNumber != 0 {
t.Errorf("ASN.ListAS(0)!=0: data should not be alterable")
}
} else {
t.Errorf("ASN.ListAS(0) not found, went missing after alteration")
}
}
})
}
}