This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
forked from jwhited/corebgp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacket_test.go
168 lines (164 loc) · 2.69 KB
/
packet_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package corebgp
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCapability_Equal(t *testing.T) {
type fields struct {
Code uint8
Value []byte
}
type args struct {
d Capability
}
tests := []struct {
name string
fields fields
args args
want bool
}{
{
name: "equal",
fields: fields{
Code: 1,
Value: []byte{1},
},
args: args{
d: Capability{
Code: 1,
Value: []byte{1},
},
},
want: true,
},
{
name: "unequal code",
fields: fields{
Code: 1,
Value: []byte{1},
},
args: args{
d: Capability{
Code: 2,
Value: []byte{1},
},
},
want: false,
},
{
name: "unequal value",
fields: fields{
Code: 1,
Value: []byte{1},
},
args: args{
d: Capability{
Code: 1,
Value: []byte{2},
},
},
want: false,
},
{
name: "equal nil and empty value",
fields: fields{
Code: 1,
Value: []byte{},
},
args: args{
d: Capability{
Code: 1,
Value: nil,
},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := Capability{
Code: tt.fields.Code,
Value: tt.fields.Value,
}
assert.Equalf(t, tt.want, c.Equal(tt.args.d), "Equal(%v)", tt.args.d)
})
}
}
func TestDecodeAddPathTuples(t *testing.T) {
type args struct {
b []byte
}
tests := []struct {
name string
args args
want []AddPathTuple
wantErr assert.ErrorAssertionFunc
}{
{
name: "valid tuples",
args: args{
b: []byte{
0x00, 0x01, // afi
0x01, // safi
0x02, // tx
0x00, 0x02, // afi
0x01, // safi
0x01, // tx
0x00, 0x03, // afi
0x01, // safi
0x03, // tx
},
},
want: []AddPathTuple{
{
AFI: 1,
SAFI: 1,
Tx: true,
},
{
AFI: 2,
SAFI: 1,
Rx: true,
},
{
AFI: 3,
SAFI: 1,
Tx: true,
Rx: true,
},
},
wantErr: assert.NoError,
},
{
name: "invalid tuple on tail",
args: args{
b: []byte{
0x00, 0x01, // afi
0x01, // safi
0x02, // tx
0x00, 0x02, // afi
0x01, // safi
0x01, // tx
0x00, 0x03, // afi
0x01, // safi
0x03, // tx
0x00, 0x03, // afi
0x01, // safi
// no direction octet
},
},
want: nil,
wantErr: assert.Error,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := DecodeAddPathTuples(tt.args.b)
if !tt.wantErr(t, err, fmt.Sprintf("DecodeAddPathTuples(%v)", tt.args.b)) {
return
}
assert.Equalf(t, tt.want, got, "DecodeAddPathTuples(%v)", tt.args.b)
})
}
}