summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_relay_agent_information_test.go
blob: a875d14ece9a620154694cb7c0e26e78dab04004 (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
package dhcpv4

import (
	"testing"

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

func TestGetRelayAgentInformation(t *testing.T) {
	m, _ := New(WithGeneric(OptionRelayAgentInformation, []byte{
		1, 5, 'l', 'i', 'n', 'u', 'x',
		2, 4, 'b', 'o', 'o', 't',
	}))

	opt := m.RelayAgentInfo()
	require.NotNil(t, opt)
	require.Equal(t, len(opt.Options), 2)

	circuit := opt.Get(GenericOptionCode(1))
	remote := opt.Get(GenericOptionCode(2))
	require.Equal(t, circuit, []byte("linux"))
	require.Equal(t, remote, []byte("boot"))

	// Empty.
	m, _ = New()
	require.Nil(t, m.RelayAgentInfo())

	// Invalid contents.
	m, _ = New(WithGeneric(OptionRelayAgentInformation, []byte{
		1, 7, 'l', 'i', 'n', 'u', 'x',
	}))
	require.Nil(t, m.RelayAgentInfo())
}

func TestOptRelayAgentInfo(t *testing.T) {
	opt := OptRelayAgentInfo(
		OptGeneric(GenericOptionCode(1), []byte("linux")),
		OptGeneric(GenericOptionCode(2), []byte("boot")),
	)
	wantBytes := []byte{
		1, 5, 'l', 'i', 'n', 'u', 'x',
		2, 4, 'b', 'o', 'o', 't',
	}
	wantString := "Relay Agent Information:\n\n    Agent Circuit ID Sub-option: linux ([108 105 110 117 120])\n    Agent Remote ID Sub-option: boot ([98 111 111 116])\n"
	require.Equal(t, wantBytes, opt.Value.ToBytes())
	require.Equal(t, OptionRelayAgentInformation, opt.Code)
	require.Equal(t, wantString, opt.String())
}