summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_domain_search_test.go
blob: 590ccd0b63bdde0e7f751bc7e838dba984c452c2 (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
package dhcpv4

import (
	"testing"

	"github.com/insomniacslk/dhcp/rfc1035label"
	"github.com/stretchr/testify/require"
)

func TestParseOptDomainSearch(t *testing.T) {
	data := []byte{
		119, // OptionDNSDomainSearchList
		33,  // length
		7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'c', 'o', 'm', 0,
		6, 's', 'u', 'b', 'n', 'e', 't', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'o', 'r', 'g', 0,
	}
	opt, err := ParseOptDomainSearch(data)
	require.NoError(t, err)
	require.Equal(t, 2, len(opt.DomainSearch.Labels))
	require.Equal(t, data[2:], opt.DomainSearch.ToBytes())
	require.Equal(t, len(data[2:]), opt.DomainSearch.Length())
	require.Equal(t, opt.DomainSearch.Labels[0], "example.com")
	require.Equal(t, opt.DomainSearch.Labels[1], "subnet.example.org")
}

func TestOptDomainSearchToBytes(t *testing.T) {
	expected := []byte{
		119, // OptionDNSDomainSearchList
		33,  // length
		7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'c', 'o', 'm', 0,
		6, 's', 'u', 'b', 'n', 'e', 't', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'o', 'r', 'g', 0,
	}
	opt := OptDomainSearch{
		DomainSearch: &rfc1035label.Labels{
			Labels: []string{
				"example.com",
				"subnet.example.org",
			},
		},
	}
	require.Equal(t, opt.ToBytes(), expected)
}