summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/bsdp/option_vendor_specific_information_test.go
blob: a6727f566e973f2ec125f389a2f4d3c150322fcc (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package bsdp

import (
	"net"
	"testing"

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

func TestOptVendorSpecificInformationInterfaceMethods(t *testing.T) {
	o := OptVendorOptions(
		OptVersion(Version1_1),
		OptMessageType(MessageTypeList),
	)
	require.Equal(t, dhcpv4.OptionVendorSpecificInformation, o.Code, "Code")

	expectedBytes := []byte{
		1, 1, 1, // List option
		2, 2, 1, 1, // Version option
	}
	require.Equal(t, expectedBytes, o.Value.ToBytes(), "ToBytes")
}

func TestOptVendorSpecificInformationString(t *testing.T) {
	o := OptVendorOptions(
		OptMessageType(MessageTypeList),
		OptVersion(Version1_1),
	)
	expectedString := "Vendor Specific Information:\n    BSDP Message Type: LIST\n    BSDP Version: 1.1\n"
	require.Equal(t, expectedString, o.String())

	// Test more complicated string - sub options of sub options.
	o = OptVendorOptions(
		OptMessageType(MessageTypeList),
		OptBootImageList(
			BootImage{
				ID: BootImageID{
					IsInstall: false,
					ImageType: BootImageTypeMacOSX,
					Index:     1001,
				},
				Name: "bsdp-1",
			},
			BootImage{
				ID: BootImageID{
					IsInstall: true,
					ImageType: BootImageTypeMacOS9,
					Index:     9009,
				},
				Name: "bsdp-2",
			},
		),
		OptMachineName("foo"),
		OptServerIdentifier(net.IP{1, 1, 1, 1}),
		OptServerPriority(1234),
		OptReplyPort(1235),
		OptDefaultBootImageID(BootImageID{
			IsInstall: true,
			ImageType: BootImageTypeMacOS9,
			Index:     9009,
		}),
		OptSelectedBootImageID(BootImageID{
			IsInstall: true,
			ImageType: BootImageTypeMacOS9,
			Index:     9009,
		}),
	)
	expectedString = "Vendor Specific Information:\n" +
		"    BSDP Message Type: LIST\n" +
		"    BSDP Server Identifier: 1.1.1.1\n" +
		"    BSDP Server Priority: 1234\n" +
		"    BSDP Reply Port: 1235\n" +
		"    BSDP Default Boot Image ID: [9009] installable macOS 9 image\n" +
		"    BSDP Selected Boot Image ID: [9009] installable macOS 9 image\n" +
		"    BSDP Boot Image List: bsdp-1 [1001] uninstallable macOS image, bsdp-2 [9009] installable macOS 9 image\n" +
		"    BSDP Machine Name: foo\n"
	require.Equal(t, expectedString, o.String())
}