summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/ztpv6/parse_vendor_options_test.go
diff options
context:
space:
mode:
authorChris Gorham <gorhamc90@gmail.com>2018-12-12 07:17:09 -0700
committerPablo Mazzini <pmazzini@gmail.com>2018-12-12 14:17:09 +0000
commit2b569280e441c779406c8b2aaa1283ca5ce0f15b (patch)
tree958baf282cbdbce007a2c566dfdec53cb2246c91 /dhcpv6/ztpv6/parse_vendor_options_test.go
parent94fe644699296ec03ad8eadfed31289b1098c5a0 (diff)
[dhcpv6/ztpv6] Adding Parsing Vendor Opts and Parsing Remote Id Opts lib for ztpv6 (#208)
Diffstat (limited to 'dhcpv6/ztpv6/parse_vendor_options_test.go')
-rw-r--r--dhcpv6/ztpv6/parse_vendor_options_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/dhcpv6/ztpv6/parse_vendor_options_test.go b/dhcpv6/ztpv6/parse_vendor_options_test.go
new file mode 100644
index 0000000..a494fac
--- /dev/null
+++ b/dhcpv6/ztpv6/parse_vendor_options_test.go
@@ -0,0 +1,55 @@
+package ztpv6
+
+import (
+ "testing"
+
+ "github.com/insomniacslk/dhcp/dhcpv6"
+ "github.com/stretchr/testify/require"
+)
+
+func TestParseVendorData(t *testing.T) {
+ tt := []struct {
+ name string
+ vc, hostname string
+ want *VendorData
+ fail bool
+ }{
+ {name: "empty", fail: true},
+ {name: "unknownVendor", vc: "VendorX;BFR10K;XX12345", fail: true, want: nil},
+ {name: "truncatedArista", vc: "Arista;1234", fail: true, want: nil},
+ {name: "truncatedZPE", vc: "ZPESystems:1234", fail: true, want: nil},
+ {
+ name: "arista",
+ vc: "Arista;DCS-7050S-64;01.23;JPE12345678",
+ want: &VendorData{VendorName: "Arista", Model: "DCS-7050S-64", Serial: "JPE12345678"},
+ }, {
+ name: "zpe",
+ vc: "ZPESystems:NSC:001234567",
+ want: &VendorData{VendorName: "ZPESystems", Model: "NSC", 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)
+ }
+
+ opts := []dhcpv6.Option{&dhcpv6.OptionGeneric{OptionData: []byte(tc.vc), OptionCode: 1}}
+ packet.AddOption(&dhcpv6.OptVendorOpts{
+ VendorOpts: opts, EnterpriseNumber: 0000})
+
+ 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")
+ }
+ })
+ }
+}