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

import (
	"testing"

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

func TestOptReplyPortInterfaceMethods(t *testing.T) {
	o := OptReplyPort{1234}
	require.Equal(t, OptionReplyPort, o.Code(), "Code")
	require.Equal(t, 2, o.Length(), "Length")
	require.Equal(t, []byte{byte(OptionReplyPort), 2, 4, 210}, o.ToBytes(), "ToBytes")
}

func TestParseOptReplyPort(t *testing.T) {
	data := []byte{0, 1}
	o, err := ParseOptReplyPort(data)
	require.NoError(t, err)
	require.Equal(t, &OptReplyPort{1}, o)

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

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

func TestOptReplyPortString(t *testing.T) {
	// known
	o := OptReplyPort{1234}
	require.Equal(t, "BSDP Reply Port -> 1234", o.String())
}