summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/ztpv4/ztp_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv4/ztpv4/ztp_test.go')
-rw-r--r--dhcpv4/ztpv4/ztp_test.go48
1 files changed, 47 insertions, 1 deletions
diff --git a/dhcpv4/ztpv4/ztp_test.go b/dhcpv4/ztpv4/ztp_test.go
index 6e050d9..d0b002f 100644
--- a/dhcpv4/ztpv4/ztp_test.go
+++ b/dhcpv4/ztpv4/ztp_test.go
@@ -4,10 +4,11 @@ import (
"testing"
"github.com/insomniacslk/dhcp/dhcpv4"
+ "github.com/insomniacslk/dhcp/iana"
"github.com/stretchr/testify/require"
)
-func TestParseV4VendorClass(t *testing.T) {
+func TestParseClassIdentifier(t *testing.T) {
tt := []struct {
name string
vc, hostname string
@@ -70,3 +71,48 @@ func TestParseV4VendorClass(t *testing.T) {
})
}
}
+
+func TestParseVIVC(t *testing.T) {
+ tt := []struct {
+ name string
+ vivc string
+ entID iana.EntID
+ want *VendorData
+ fail bool
+ }{
+ {
+ name: "cisco",
+ entID: iana.EntIDCiscoSystems,
+ vivc: "SN:0;PID:R-IOSXRV9000-CC",
+ want: &VendorData{VendorName: "Cisco Systems", Model: "R-IOSXRV9000-CC", Serial: "0"},
+ },
+ {
+ name: "ciscoMultipleColonDelimiters",
+ entID: iana.EntIDCiscoSystems,
+ vivc: "SN:0:123;PID:R-IOSXRV9000-CC:456",
+ fail: true,
+ },
+ }
+
+ for _, tc := range tt {
+ t.Run(tc.name, func(t *testing.T) {
+ packet, err := dhcpv4.New()
+ if err != nil {
+ t.Fatalf("failed to creat dhcpv4 packet object: %v", err)
+ }
+
+ if tc.vivc != "" {
+ vivc := dhcpv4.VIVCIdentifier{EntID: uint32(tc.entID), Data: []byte(tc.vivc)}
+ packet.UpdateOption(dhcpv4.OptVIVC(vivc))
+ }
+
+ vd, err := ParseVendorData(packet)
+ if tc.fail {
+ require.Error(t, err)
+ } else {
+ require.NoError(t, err)
+ require.Equal(t, tc.want, vd)
+ }
+ })
+ }
+}