forked from tinkerbell/smee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dhcp_test.go
58 lines (52 loc) · 1.48 KB
/
dhcp_test.go
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
package main
import (
"testing"
"github.com/packethost/dhcp4-go"
)
func TestGetCircuitID(t *testing.T) {
for _, test := range []struct {
name string
option dhcp4.Option
optionvalue []byte
expected string
err string // logged error description
}{
{
name: "With option82 circuitid",
option: dhcp4.OptionRelayAgentInformation,
optionvalue: []byte("\x01\x19esr1.d11.lab1:ge-1/0/47.0\x02\x0Bge-1/0/47.0"),
expected: "esr1.d11.lab1:ge-1/0/47",
err: "",
},
{
name: "No option82 information",
option: dhcp4.OptionEnd, // option not important here, just needs to not have OptionRelayAgentInformation
optionvalue: []byte{},
expected: "",
err: "option82 information not available for this mac",
},
{
name: "Malformed option82",
option: dhcp4.OptionRelayAgentInformation,
optionvalue: []byte("\x01\x19esr1.d11.la"),
expected: "",
err: "option82 option1 out of bounds (check eightytwo[1])",
},
} {
t.Log(test.name)
var packet = new(dhcp4.Packet)
packet.OptionMap = make(dhcp4.OptionMap, 255)
packet.SetOption(test.option, test.optionvalue)
c, err := getCircuitID(packet)
if err != nil {
if err.Error() != test.err {
t.Fatalf("unexpected error, want: %s, got: %s", test.err, err)
}
}
if c != "" {
if c != test.expected {
t.Fatalf("expected value not returned for option82, want: %s, got: %s", test.expected, c)
}
}
}
}