summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_bootfileurl_test.go
blob: f93dc47d2148e0b1597c6b2ac677ae6e9ff11957 (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
package dhcpv6

import (
	"bytes"
	"testing"

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

func TestOptBootFileURL(t *testing.T) {
	expected := []byte("https://insomniac.slackware.it")
	opt, err := ParseOptBootFileURL(expected)
	if err != nil {
		t.Fatal(err)
	}
	if optLen := opt.Length(); optLen != len(expected) {
		t.Fatalf("Invalid length. Expected %v, got %v", len(expected), optLen)
	}
	if url := opt.BootFileURL; !bytes.Equal(url, expected) {
		t.Fatalf("Invalid boot file URL. Expected %v, got %v", expected, url)
	}
	require.Contains(t, opt.String(), "BootFileUrl=https://insomniac.slackware.it", "String() should contain the correct BootFileUrl output")
}

func TestOptBootFileURLToBytes(t *testing.T) {
	urlString := []byte("https://insomniac.slackware.it")
	expected := []byte{00, 59, 00, byte(len(urlString))}
	expected = append(expected, urlString...)
	opt := OptBootFileURL{
		BootFileURL: urlString,
	}
	toBytes := opt.ToBytes()
	if !bytes.Equal(toBytes, expected) {
		t.Fatalf("Invalid ToBytes result. Expected %v, got %v", expected, toBytes)
	}
}