summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_relay_agent_information_test.go
blob: bb5fae0a93d0a3682b016c237bff19d7006362bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package dhcpv4

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestParseOptRelayAgentInformation(t *testing.T) {
	data := []byte{
		1, 5, 'l', 'i', 'n', 'u', 'x',
		2, 4, 'b', 'o', 'o', 't',
	}

	// short sub-option bytes
	opt, err := ParseOptRelayAgentInformation([]byte{1, 0, 1})
	require.Error(t, err)

	// short sub-option length
	opt, err = ParseOptRelayAgentInformation([]byte{1, 1})
	require.Error(t, err)

	opt, err = ParseOptRelayAgentInformation(data)
	require.NoError(t, err)
	require.Equal(t, len(opt.Options), 2)
	circuit := opt.Options.GetOne(optionCode(1)).(*OptionGeneric)
	require.NoError(t, err)
	remote := opt.Options.GetOne(optionCode(2)).(*OptionGeneric)
	require.NoError(t, err)
	require.Equal(t, circuit.Data, []byte("linux"))
	require.Equal(t, remote.Data, []byte("boot"))
}

func TestParseOptRelayAgentInformationToBytes(t *testing.T) {
	opt := OptRelayAgentInformation{
		Options: Options{
			&OptionGeneric{OptionCode: optionCode(1), Data: []byte("linux")},
			&OptionGeneric{OptionCode: optionCode(2), Data: []byte("boot")},
		},
	}
	data := opt.ToBytes()
	expected := []byte{
		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())
}