diff options
author | Owen Mooney <mooneyow@tcd.ie> | 2018-07-25 13:14:11 +0100 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2018-07-25 13:14:11 +0100 |
commit | fdac804dc9375ebe7c607059c186b771d5c49800 (patch) | |
tree | 5651a7ad28111b531b3396c83148dd17551bde61 /dhcpv4/option_tftp_server_name_test.go | |
parent | b9bd21d7d9cb3fb12761808f11d9a40d9d01558e (diff) |
Add TFTP server name option (#92)
Diffstat (limited to 'dhcpv4/option_tftp_server_name_test.go')
-rw-r--r-- | dhcpv4/option_tftp_server_name_test.go | 60 |
1 files changed, 60 insertions, 0 deletions
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) +} |