-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbgpwatch_test.go
63 lines (59 loc) · 1.04 KB
/
bgpwatch_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
package main
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestGetRid(t *testing.T) {
tests := []struct {
desc string
srid string
wantErr bool
want bgpid
}{
{
desc: "empty",
wantErr: true,
},
{
desc: "wrong format",
srid: "1.1.1.1.1",
wantErr: true,
},
{
desc: "wrong format - IPv6",
srid: "2001::db8",
wantErr: true,
},
{
desc: "wrong format - letter",
srid: "0.0.0.a",
wantErr: true,
},
{
desc: "default RID",
srid: "0.0.0.1",
want: bgpid{0x0, 0x0, 0x0, 0x1},
},
{
desc: "regular RID",
srid: "9.8.7.6",
want: bgpid{0x9, 0x8, 0x7, 0x6},
},
{
desc: "max RID",
srid: "255.255.255.255",
want: bgpid{0xff, 0xff, 0xff, 0xff},
},
}
for _, test := range tests {
got, err := getRid(&test.srid)
if test.wantErr {
if err == nil {
t.Errorf("Test (%s): wanted error but none received", test.desc)
}
}
if !cmp.Equal(got, test.want) {
t.Errorf("Test (%s): got %#v, want %#v", test.desc, got, test.want)
}
}
}