forked from jwhited/bgpls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet_notification_test.go
46 lines (37 loc) · 853 Bytes
/
packet_notification_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
package bgpls
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNotificationMessage(t *testing.T) {
code := NotifErrCodeUpdateMessage
subcode := NotifErrSubcodeMalformedAttr
data := []byte{1, 1, 1, 1}
n := &NotificationMessage{
Code: code,
Subcode: subcode,
Data: data,
}
b, err := n.serialize()
if err != nil {
t.Error(err)
}
m, err := messagesFromBytes(b)
if err != nil {
t.Error(err)
}
if len(m) != 1 {
t.Errorf("invalid number of messages deserialized: %d", len(m))
}
f, ok := m[0].(*NotificationMessage)
if !ok {
t.Error("not a notification message")
}
assert.Equal(t, f.MessageType(), NotificationMessageType)
assert.Equal(t, code, f.Code)
assert.Equal(t, subcode, f.Subcode)
assert.Equal(t, len(data), len(f.Data))
for i, d := range data {
assert.Equal(t, d, f.Data[i])
}
}