File: option_requestedoption_test.go

package info (click to toggle)
golang-github-insomniacslk-dhcp 0.0~git20220915.043f172-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,168 kB
  • sloc: makefile: 6
file content (41 lines) | stat: -rw-r--r-- 993 bytes parent folder | download | duplicates (2)
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
package dhcpv6

import (
	"testing"

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

func TestOptRequestedOption(t *testing.T) {
	expected := []byte{0, 1, 0, 2}
	var o optRequestedOption
	err := o.FromBytes(expected)
	require.NoError(t, err, "ParseOptRequestedOption() correct options should not error")
}

func TestOptRequestedOptionParseOptRequestedOptionTooShort(t *testing.T) {
	buf := []byte{0, 1, 0}
	var o optRequestedOption
	err := o.FromBytes(buf)
	require.Error(t, err, "A short option should return an error (must be divisible by 2)")
}

func TestOptRequestedOptionString(t *testing.T) {
	buf := []byte{0, 1, 0, 2}
	var o optRequestedOption
	err := o.FromBytes(buf)
	require.NoError(t, err)
	require.Contains(
		t,
		o.String(),
		"Client Identifier, Server Identifier",
		"String() should contain the options specified",
	)
	o.OptionCodes = append(o.OptionCodes, 12345)
	require.Contains(
		t,
		o.String(),
		"unknown",
		"String() should contain 'Unknown' for an illegal option",
	)
}