diff options
Diffstat (limited to 'dhcpv4/option_subnet_mask_test.go')
-rw-r--r-- | dhcpv4/option_subnet_mask_test.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/dhcpv4/option_subnet_mask_test.go b/dhcpv4/option_subnet_mask_test.go new file mode 100644 index 0000000..4cb8819 --- /dev/null +++ b/dhcpv4/option_subnet_mask_test.go @@ -0,0 +1,44 @@ +package dhcpv4 + +import ( + "net" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestOptSubnetMaskInterfaceMethods(t *testing.T) { + mask := net.IPMask{255, 255, 255, 0} + o := OptSubnetMask{SubnetMask: mask} + + require.Equal(t, OptionSubnetMask, o.Code(), "Code") + + expectedBytes := []byte{1, 4, 255, 255, 255, 0} + require.Equal(t, expectedBytes, o.ToBytes(), "ToBytes") + + require.Equal(t, 4, o.Length(), "Length") + + require.Equal(t, "Subnet Mask -> ffffff00", o.String(), "String") +} + +func TestParseOptSubnetMask(t *testing.T) { + var ( + o *OptSubnetMask + err error + ) + o, err = ParseOptSubnetMask([]byte{}) + require.Error(t, err, "empty byte stream") + + o, err = ParseOptSubnetMask([]byte{1, 4, 255}) + require.Error(t, err, "short byte stream") + + o, err = ParseOptSubnetMask([]byte{1, 3, 255, 255, 255, 0}) + require.Error(t, err, "wrong IP length") + + o, err = ParseOptSubnetMask([]byte{2, 4, 255, 255, 255}) + require.Error(t, err, "wrong option code") + + o, err = ParseOptSubnetMask([]byte{1, 4, 255, 255, 255, 0}) + require.NoError(t, err) + require.Equal(t, net.IPMask{255, 255, 255, 0}, o.SubnetMask) +} |