summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_dnsrecursivenameserver_test.go
blob: 71fe6d3275237dace422934c00966990ff656ffa (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
package dhcpv6

import (
	"net"
	"testing"

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

func TestParseOptDNSRecursiveNameServer(t *testing.T) {
	data := []byte{
		0x2a, 0x03, 0x28, 0x80, 0xff, 0xfe, 0x00, 0x0c, 0xfa, 0xce, 0xb0, 0x0c, 0x00, 0x00, 0x00, 0x35,
	}
	expected := []net.IP{
		net.IP(data),
	}
	opt, err := ParseOptDNSRecursiveNameServer(data)
	require.NoError(t, err)
	require.Equal(t, opt.NameServers, expected)
	require.Equal(t, opt.Length(), 16)
}

func TestOptDNSRecursiveNameServerToBytes(t *testing.T) {
	ns1 := net.ParseIP("2a03:2880:fffe:c:face:b00c:0:35")
	ns2 := net.ParseIP("2001:4860:4860::8888")
	nameservers := []net.IP{ns1, ns2}
	expected := []byte{
		0, 23, // OptionDNSRecursiveNameServer
		0, 32, // length
	}
	expected = append(expected, []byte(ns1)...)
	expected = append(expected, []byte(ns2)...)
	opt := OptDNSRecursiveNameServer{NameServers: nameservers}
	require.Equal(t, opt.ToBytes(), expected)
}