From fdac804dc9375ebe7c607059c186b771d5c49800 Mon Sep 17 00:00:00 2001 From: Owen Mooney Date: Wed, 25 Jul 2018 13:14:11 +0100 Subject: Add TFTP server name option (#92) --- dhcpv4/option_tftp_server_name_test.go | 60 ++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 dhcpv4/option_tftp_server_name_test.go (limited to 'dhcpv4/option_tftp_server_name_test.go') diff --git a/dhcpv4/option_tftp_server_name_test.go b/dhcpv4/option_tftp_server_name_test.go new file mode 100644 index 0000000..caddf95 --- /dev/null +++ b/dhcpv4/option_tftp_server_name_test.go @@ -0,0 +1,60 @@ +package dhcpv4 + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestOptTFTPServerNameCode(t *testing.T) { + opt := OptTFTPServerName{} + require.Equal(t, OptionTFTPServerName, opt.Code()) +} + +func TestOptTFTPServerNameToBytes(t *testing.T) { + opt := OptTFTPServerName{ + TFTPServerName: []byte("linuxboot"), + } + data := opt.ToBytes() + expected := []byte{ + 66, // OptionTFTPServerName + 9, // length + 'l', 'i', 'n', 'u', 'x', 'b', 'o', 'o', 't', + } + require.Equal(t, expected, data) +} + +func TestParseOptTFTPServerName(t *testing.T) { + expected := []byte{ + 66, 9, 'l', 'i', 'n', 'u', 'x', 'b', 'o', 'o', 't', + } + opt, err := ParseOptTFTPServerName(expected) + require.NoError(t, err) + require.Equal(t, 9, opt.Length()) + require.Equal(t, "linuxboot", string(opt.TFTPServerName)) +} + +func TestParseOptTFTPServerNameZeroLength(t *testing.T) { + expected := []byte{ + 66, 0, + } + _, err := ParseOptTFTPServerName(expected) + require.Error(t, err) +} + +func TestParseOptTFTPServerNameInvalidLength(t *testing.T) { + expected := []byte{ + 66, 9, 'l', 'i', 'n', 'u', 'x', 'b', + } + _, err := ParseOptTFTPServerName(expected) + require.Error(t, err) +} + +func TestParseOptTFTPServerNameShortLength(t *testing.T) { + expected := []byte{ + 66, 4, 'l', 'i', 'n', 'u', 'x', + } + opt, err := ParseOptTFTPServerName(expected) + require.NoError(t, err) + require.Equal(t, []byte("linu"), opt.TFTPServerName) +} -- cgit v1.2.3