diff options
Diffstat (limited to 'dhcpv6/ztpv6/parse_vendor_options_test.go')
-rw-r--r-- | dhcpv6/ztpv6/parse_vendor_options_test.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/dhcpv6/ztpv6/parse_vendor_options_test.go b/dhcpv6/ztpv6/parse_vendor_options_test.go index 45b42d6..ac5fc81 100644 --- a/dhcpv6/ztpv6/parse_vendor_options_test.go +++ b/dhcpv6/ztpv6/parse_vendor_options_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/insomniacslk/dhcp/dhcpv6" + "github.com/insomniacslk/dhcp/iana" "github.com/stretchr/testify/require" ) @@ -99,3 +100,50 @@ func TestParseVendorDataWithVendorClass(t *testing.T) { }) } } + +func TestParseVendorDataWithClientId(t *testing.T) { + tt := []struct { + name string + vc string + serial string + want *VendorData + fail bool + }{ + { + name: "Ciena", + vc: "1271-23422Z11-123", + serial: "001234567", + want: &VendorData{VendorName: iana.EnterpriseIDCienaCorporation.String(), Model: "23422Z11-123", Serial: "001234567"}, + }, + } + + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + packet, err := dhcpv6.NewMessage() + if err != nil { + t.Fatalf("failed to creat dhcpv6 packet object: %v", err) + } + + packet.AddOption(&dhcpv6.OptVendorClass{ + EnterpriseNumber: 0000, Data: [][]byte{[]byte(tc.vc)}}) + packet.AddOption(dhcpv6.OptClientID( + dhcpv6.Duid{ + Type: dhcpv6.DUID_EN, + EnterpriseIdentifier: []byte(tc.serial), + }, + ), + ) + + vd, err := ParseVendorData(packet) + if err != nil && !tc.fail { + t.Errorf("unexpected failure: %v", err) + } + + if vd != nil { + require.Equal(t, *tc.want, *vd, "comparing vendor option data") + } else { + require.Equal(t, tc.want, vd, "comparing vendor option data") + } + }) + } +} |