diff options
author | insomniac <insomniacslk@users.noreply.github.com> | 2018-11-12 13:46:50 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-12 13:46:50 +0000 |
commit | 22ab333fff995af78b17bb533de93317fc7b65d5 (patch) | |
tree | ad115cae67c2d5f96b97d868727b30dc3818f681 /dhcpv4/option_relay_agent_information_test.go | |
parent | 08eace5b3537c9cedf8fbf2f2a61562e3ffbc302 (diff) | |
parent | 5ee47520014b0835b58e3624381e01bdf14ef9ba (diff) |
add OptRelayAgentInformation (#193)
Diffstat (limited to 'dhcpv4/option_relay_agent_information_test.go')
-rw-r--r-- | dhcpv4/option_relay_agent_information_test.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go new file mode 100644 index 0000000..1e99206 --- /dev/null +++ b/dhcpv4/option_relay_agent_information_test.go @@ -0,0 +1,67 @@ +package dhcpv4 + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestParseOptRelayAgentInformation(t *testing.T) { + data := []byte{ + byte(OptionRelayAgentInformation), + 13, + 1, 5, 'l', 'i', 'n', 'u', 'x', + 2, 4, 'b', 'o', 'o', 't', + } + + // short option bytes + opt, err := ParseOptRelayAgentInformation([]byte{}) + require.Error(t, err) + + // wrong code + opt, err = ParseOptRelayAgentInformation([]byte{1, 2, 1, 0}) + require.Error(t, err) + + // wrong option length + opt, err = ParseOptRelayAgentInformation([]byte{82, 3, 1, 0}) + require.Error(t, err) + + // short sub-option bytes + opt, err = ParseOptRelayAgentInformation([]byte{82, 3, 1, 0, 1}) + require.Error(t, err) + + // short sub-option length + opt, err = ParseOptRelayAgentInformation([]byte{82, 2, 1, 1}) + require.Error(t, err) + + opt, err = ParseOptRelayAgentInformation(data) + require.NoError(t, err) + require.Equal(t, len(opt.Options), 2) + circuit, ok := opt.Options[0].(*OptionGeneric) + require.True(t, ok) + remote, ok := opt.Options[1].(*OptionGeneric) + require.True(t, ok) + require.Equal(t, circuit.Data, []byte("linux")) + require.Equal(t, remote.Data, []byte("boot")) +} + +func TestParseOptRelayAgentInformationToBytes(t *testing.T) { + opt := OptRelayAgentInformation{} + opt1 := &OptionGeneric{OptionCode: 1, Data: []byte("linux")} + opt.Options = append(opt.Options, opt1) + opt2 := &OptionGeneric{OptionCode: 2, Data: []byte("boot")} + opt.Options = append(opt.Options, opt2) + data := opt.ToBytes() + expected := []byte{ + byte(OptionRelayAgentInformation), + 13, + 1, 5, 'l', 'i', 'n', 'u', 'x', + 2, 4, 'b', 'o', 'o', 't', + } + require.Equal(t, expected, data) +} + +func TestOptRelayAgentInformationToBytesString(t *testing.T) { + o := OptRelayAgentInformation{} + require.Equal(t, "Relay Agent Information -> []", o.String()) +} |