Newer
Older
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
package routingtable
import (
"fmt"
"testing"
)
func TestFancy(t *testing.T) {
c := NewContributingASNs()
tests := []struct {
runCmd func()
expect func() bool
msg string
}{
// Empty list
{
runCmd: func() {},
expect: func() bool { return !c.IsContributingASN(41981) },
msg: "AS41981 shouldn't be contributing yet.",
},
// Add and remove one ASN
{
runCmd: func() { c.Add(41981) },
expect: func() bool { return c.IsContributingASN(41981) },
msg: "AS41981 should be contributing",
},
{
runCmd: func() { c.Remove(41981) },
expect: func() bool { return !c.IsContributingASN(41981) },
msg: "AS41981 shouldn't be contributing no more.",
},
// Two ASNs present
{
runCmd: func() { c.Add(41981) },
expect: func() bool { return c.IsContributingASN(41981) },
msg: "AS41981 should be contributing",
},
{
runCmd: func() { c.Add(201701) },
expect: func() bool { return c.IsContributingASN(41981) },
msg: "AS201701 should be contributing",
},
// Add AS41981 2nd time
{
runCmd: func() { c.Add(41981) },
expect: func() bool { return c.IsContributingASN(41981) },
msg: "AS41981 should be still contributing",
},
{
runCmd: func() {},
expect: func() bool { return c.contributingASNs[0].asn == 41981 },
msg: "AS41981 is first ASN in list",
},
{
runCmd: func() { fmt.Printf("%+v", c.contributingASNs) },
expect: func() bool { return c.contributingASNs[0].count == 2 },
msg: "AS41981 should be present twice.",
},
}
for i, test := range tests {
test.runCmd()
if !test.expect() {
t.Errorf("Test %d failed: %v", i, test.msg)
}
}
}