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
|
package dhcpv4
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestParseOptionGeneric(t *testing.T) {
// Empty bytestream produces error
_, err := ParseOptionGeneric(OptionHostName, []byte{})
require.Error(t, err, "error from empty bytestream")
}
func TestOptionGenericCode(t *testing.T) {
o := OptionGeneric{
OptionCode: OptionDHCPMessageType,
Data: []byte{byte(MessageTypeDiscover)},
}
require.Equal(t, OptionDHCPMessageType, o.Code())
}
func TestOptionGenericToBytes(t *testing.T) {
o := OptionGeneric{
OptionCode: OptionDHCPMessageType,
Data: []byte{byte(MessageTypeDiscover)},
}
serialized := o.ToBytes()
expected := []byte{1}
require.Equal(t, expected, serialized)
}
func TestOptionGenericString(t *testing.T) {
o := OptionGeneric{
OptionCode: OptionDHCPMessageType,
Data: []byte{byte(MessageTypeDiscover)},
}
require.Equal(t, "DHCP Message Type -> [1]", o.String())
}
func TestOptionGenericStringUnknown(t *testing.T) {
o := OptionGeneric{
OptionCode: optionCode(102), // Returned option code.
Data: []byte{byte(MessageTypeDiscover)},
}
require.Equal(t, "unknown -> [1]", o.String())
}
|