File: option_fqdn_test.go

package info (click to toggle)
golang-github-insomniacslk-dhcp 0.0~git20220915.043f172-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,168 kB
  • sloc: makefile: 6
file content (42 lines) | stat: -rw-r--r-- 939 bytes parent folder | download | duplicates (2)
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 dhcpv6

import (
	"bytes"
	"testing"

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

func TestParseOptFQDN(t *testing.T) {
	data := []byte{
		0, // Flags
		4, 'c', 'n', 'o', 's', 9, 'l', 'o', 'c', 'a', 'l',
		'h', 'o', 's', 't', 0,
	}
	opt, err := ParseOptFQDN(data)

	require.NoError(t, err)
	require.Equal(t, OptionFQDN, opt.Code())
	require.Equal(t, uint8(0), opt.Flags)
	require.Equal(t, "cnos.localhost", opt.DomainName.Labels[0])
	require.Equal(t, "OptFQDN{flags=0, domainname=[cnos.localhost]}", opt.String())
}

func TestOptFQDNToBytes(t *testing.T) {
	opt := OptFQDN{
		Flags:      0,
		DomainName: &rfc1035label.Labels{
			Labels: []string{"cnos.localhost"},
		},
	}
	want := []byte{
		0, // Flags
		4, 'c', 'n', 'o', 's', 9, 'l', 'o', 'c', 'a', 'l',
		'h', 'o', 's', 't', 0,
	}
	b := opt.ToBytes()
	if !bytes.Equal(b, want) {
		t.Fatalf("opt.ToBytes()=%v, want %v", b, want)
	}
}