From bb95a0335e44a76a1e061b5dea2b1592c55177ac Mon Sep 17 00:00:00 2001 From: Sean Karlage Date: Mon, 26 Mar 2018 15:40:59 -0700 Subject: Add some more specific bsdp options + vendor specific implementation (#21) Add some more specific options + vendor specific implementation --- dhcpv4/bsdp/bsdp_option_generic_test.go | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 dhcpv4/bsdp/bsdp_option_generic_test.go (limited to 'dhcpv4/bsdp/bsdp_option_generic_test.go') diff --git a/dhcpv4/bsdp/bsdp_option_generic_test.go b/dhcpv4/bsdp/bsdp_option_generic_test.go new file mode 100644 index 0000000..5a5ad25 --- /dev/null +++ b/dhcpv4/bsdp/bsdp_option_generic_test.go @@ -0,0 +1,66 @@ +// +build darwin + +package bsdp + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestParseOptGeneric(t *testing.T) { + // Empty bytestream produces error + _, err := ParseOptGeneric([]byte{}) + require.Error(t, err, "error from empty bytestream") +} + +func TestOptGenericCode(t *testing.T) { + o := OptGeneric{ + OptionCode: OptionMessageType, + Data: []byte{byte(MessageTypeList)}, + } + require.Equal(t, OptionMessageType, o.Code()) +} + +func TestOptGenericData(t *testing.T) { + o := OptGeneric{ + OptionCode: OptionServerIdentifier, + Data: []byte{192, 168, 0, 1}, + } + require.Equal(t, []byte{192, 168, 0, 1}, o.Data) +} + +func TestOptGenericToBytes(t *testing.T) { + o := OptGeneric{ + OptionCode: OptionServerIdentifier, + Data: []byte{192, 168, 0, 1}, + } + serialized := o.ToBytes() + expected := []byte{3, 4, 192, 168, 0, 1} + require.Equal(t, expected, serialized) +} + +func TestOptGenericString(t *testing.T) { + o := OptGeneric{ + OptionCode: OptionServerIdentifier, + Data: []byte{192, 168, 0, 1}, + } + require.Equal(t, "BSDP Server Identifier -> [192 168 0 1]", o.String()) +} + +func TestOptGenericStringUnknown(t *testing.T) { + o := OptGeneric{ + OptionCode: 102, // Returend option code. + Data: []byte{5}, + } + require.Equal(t, "Unknown -> [5]", o.String()) +} + +func TestOptGenericLength(t *testing.T) { + filename := "some_machine_name" + o := OptGeneric{ + OptionCode: OptionMachineName, + Data: []byte(filename), + } + require.Equal(t, len(filename), o.Length()) +} -- cgit v1.2.3