diff options
Diffstat (limited to 'pkg/packet/bgp/prefix_sid_test.go')
-rw-r--r-- | pkg/packet/bgp/prefix_sid_test.go | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/pkg/packet/bgp/prefix_sid_test.go b/pkg/packet/bgp/prefix_sid_test.go index 84f1312f..6457c8df 100644 --- a/pkg/packet/bgp/prefix_sid_test.go +++ b/pkg/packet/bgp/prefix_sid_test.go @@ -1,24 +1,35 @@ package bgp import ( - "reflect" + "bytes" "testing" ) -func TestUnmarshalUnicastNLRI(t *testing.T) { +func TestRoundTripPrefixSID(t *testing.T) { tests := []struct { - name string - input []byte - expect *PathAttributePrefixSID - }{} + name string + input []byte + }{ + { + name: "srv6 prefix sid", + input: []byte{0xc0, 0x28, 0x25, 0x05, 0x00, 0x22, 0x00, 0x01, 0x00, 0x1e, 0x00, 0x20, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x01, 0x00, 0x06, 0x28, 0x18, 0x10, 0x00, 0x10, 0x40}, + }, + } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := GetPathAttribute(tt.input) + attribute, err := GetPathAttribute(tt.input) + if err != nil { + t.Fatalf("test failed with error: %+v", err) + } + if err := attribute.DecodeFromBytes(tt.input); err != nil { + t.Fatalf("test failed with error: %+v", err) + } + recovered, err := attribute.Serialize() if err != nil { t.Fatalf("test failed with error: %+v", err) } - if !reflect.DeepEqual(tt.expect, got) { - t.Fatalf("test failed as expected nlri %+v does not match actual nlri %+v", tt.expect, got) + if bytes.Compare(tt.input, recovered) != 0 { + t.Fatalf("round trip conversion test failed as expected prefix sid attribute %+v does not match actual: %+v", tt.input, recovered) } }) } |