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
58
59
60
|
package dhcpv4
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestOptTFTPServerNameCode(t *testing.T) {
opt := OptTFTPServerName{}
require.Equal(t, OptionTFTPServerName, opt.Code())
}
func TestOptTFTPServerNameToBytes(t *testing.T) {
opt := OptTFTPServerName{
TFTPServerName: []byte("linuxboot"),
}
data := opt.ToBytes()
expected := []byte{
66, // OptionTFTPServerName
9, // length
'l', 'i', 'n', 'u', 'x', 'b', 'o', 'o', 't',
}
require.Equal(t, expected, data)
}
func TestParseOptTFTPServerName(t *testing.T) {
expected := []byte{
66, 9, 'l', 'i', 'n', 'u', 'x', 'b', 'o', 'o', 't',
}
opt, err := ParseOptTFTPServerName(expected)
require.NoError(t, err)
require.Equal(t, 9, opt.Length())
require.Equal(t, "linuxboot", string(opt.TFTPServerName))
}
func TestParseOptTFTPServerNameZeroLength(t *testing.T) {
expected := []byte{
66, 0,
}
_, err := ParseOptTFTPServerName(expected)
require.Error(t, err)
}
func TestParseOptTFTPServerNameInvalidLength(t *testing.T) {
expected := []byte{
66, 9, 'l', 'i', 'n', 'u', 'x', 'b',
}
_, err := ParseOptTFTPServerName(expected)
require.Error(t, err)
}
func TestParseOptTFTPServerNameShortLength(t *testing.T) {
expected := []byte{
66, 4, 'l', 'i', 'n', 'u', 'x',
}
opt, err := ParseOptTFTPServerName(expected)
require.NoError(t, err)
require.Equal(t, []byte("linu"), opt.TFTPServerName)
}
|