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

import (
	"testing"

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

func TestOptVersionInterfaceMethods(t *testing.T) {
	o := OptVersion{Version1_1}
	require.Equal(t, OptionVersion, o.Code(), "Code")
	require.Equal(t, []byte{1, 1}, o.ToBytes(), "ToBytes")
}

func TestParseOptVersion(t *testing.T) {
	data := []byte{1, 1}
	o, err := ParseOptVersion(data)
	require.NoError(t, err)
	require.Equal(t, &OptVersion{Version1_1}, o)

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

func TestOptVersionString(t *testing.T) {
	// known
	o := OptVersion{Version1_1}
	require.Equal(t, "BSDP Version -> 1.1", o.String())
}