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

import (
	"testing"

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

func TestParseOptGeneric(t *testing.T) {
	// Good parse
	o, err := ParseOptGeneric(OptionMessageType, []byte{1})
	require.NoError(t, err)
	require.Equal(t, OptionMessageType, o.Code())
	require.Equal(t, MessageTypeList, MessageType(o.Data[0]))
}

func TestOptGenericCode(t *testing.T) {
	o := OptGeneric{
		OptionCode: OptionMessageType,
		Data:       []byte{byte(MessageTypeList)},
	}
	require.Equal(t, OptionMessageType, o.Code())
}

func TestOptGenericData(t *testing.T) {
	o := OptGeneric{
		OptionCode: OptionServerIdentifier,
		Data:       []byte{192, 168, 0, 1},
	}
	require.Equal(t, []byte{192, 168, 0, 1}, o.Data)
}

func TestOptGenericToBytes(t *testing.T) {
	o := OptGeneric{
		OptionCode: OptionServerIdentifier,
		Data:       []byte{192, 168, 0, 1},
	}
	serialized := o.ToBytes()
	expected := []byte{192, 168, 0, 1}
	require.Equal(t, expected, serialized)
}

func TestOptGenericString(t *testing.T) {
	o := OptGeneric{
		OptionCode: OptionServerIdentifier,
		Data:       []byte{192, 168, 0, 1},
	}
	require.Equal(t, "BSDP Server Identifier -> [192 168 0 1]", o.String())
}

func TestOptGenericStringUnknown(t *testing.T) {
	o := OptGeneric{
		OptionCode: optionCode(102), // Returned option code.
		Data:       []byte{5},
	}
	require.Equal(t, "unknown -> [5]", o.String())
}