summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/bsdp/bsdp_option_selected_boot_image_id_test.go
blob: 9529e41bdc8f950c301efa83fd96e26ea8c3d593 (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
package bsdp

import (
	"testing"

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

func TestOptSelectedBootImageIDInterfaceMethods(t *testing.T) {
	b := BootImageID{IsInstall: true, ImageType: BootImageTypeMacOSX, Index: 1001}
	o := OptSelectedBootImageID{b}
	require.Equal(t, OptionSelectedBootImageID, o.Code(), "Code")
	require.Equal(t, 4, o.Length(), "Length")
	expectedBytes := []byte{byte(OptionSelectedBootImageID), 4}
	require.Equal(t, append(expectedBytes, b.ToBytes()...), o.ToBytes(), "ToBytes")
}

func TestParseOptSelectedBootImageID(t *testing.T) {
	b := BootImageID{IsInstall: true, ImageType: BootImageTypeMacOSX, Index: 1001}
	bootImageBytes := b.ToBytes()
	data := append([]byte{byte(OptionSelectedBootImageID), 4}, bootImageBytes...)
	o, err := ParseOptSelectedBootImageID(data)
	require.NoError(t, err)
	require.Equal(t, &OptSelectedBootImageID{b}, o)

	// Short byte stream
	data = []byte{byte(OptionSelectedBootImageID), 4}
	_, err = ParseOptSelectedBootImageID(data)
	require.Error(t, err, "should get error from short byte stream")

	// Wrong code
	data = []byte{54, 2, 1, 0, 0, 0}
	_, err = ParseOptSelectedBootImageID(data)
	require.Error(t, err, "should get error from wrong code")

	// Bad length
	data = []byte{byte(OptionSelectedBootImageID), 5, 1, 0, 0, 0, 0}
	_, err = ParseOptSelectedBootImageID(data)
	require.Error(t, err, "should get error from bad length")
}

func TestOptSelectedBootImageIDString(t *testing.T) {
	b := BootImageID{IsInstall: true, ImageType: BootImageTypeMacOSX, Index: 1001}
	o := OptSelectedBootImageID{b}
	require.Equal(t, "BSDP Selected Boot Image ID -> [1001] installable macOS image", o.String())

	b = BootImageID{IsInstall: false, ImageType: BootImageTypeMacOS9, Index: 1001}
	o = OptSelectedBootImageID{b}
	require.Equal(t, "BSDP Selected Boot Image ID -> [1001] uninstallable macOS 9 image", o.String())

	b = BootImageID{IsInstall: false, ImageType: BootImageType(99), Index: 1001}
	o = OptSelectedBootImageID{b}
	require.Equal(t, "BSDP Selected Boot Image ID -> [1001] uninstallable unknown image", o.String())
}