diff options
author | Andrea Barberio <insomniac@slackware.it> | 2017-12-08 16:11:11 +0000 |
---|---|---|
committer | Andrea Barberio <insomniac@slackware.it> | 2017-12-08 16:11:11 +0000 |
commit | ee15cd8efeb0ee0e722911e9827a2e45eef1f0b1 (patch) | |
tree | f2e57c8b59bf0fca758d6beb990368386b565a7f /dhcpv6/option_relaymsg_test.go | |
parent | 256d3cd222508c5b8fcc6cc1242774b10dbfa988 (diff) |
Added DHCPv6.Length() and improved relay msg parsing
Diffstat (limited to 'dhcpv6/option_relaymsg_test.go')
-rw-r--r-- | dhcpv6/option_relaymsg_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/dhcpv6/option_relaymsg_test.go b/dhcpv6/option_relaymsg_test.go new file mode 100644 index 0000000..95fb9fb --- /dev/null +++ b/dhcpv6/option_relaymsg_test.go @@ -0,0 +1,47 @@ +package dhcpv6 + +import ( + "testing" +) + +func TestRelayMsgParseOptRelayMsg(t *testing.T) { + opt, err := ParseOptRelayMsg([]byte{ + 1, // SOLICIT + 0xaa, 0xbb, 0xcc, // transaction ID + 0, 8, // option: elapsed time + 0, 2, // option length + 0, 0, // option value + }) + if err != nil { + t.Fatal(err) + } + if code := opt.Code(); code != OPTION_RELAY_MSG { + t.Fatalf("Invalid option code. Expected OPTION_RELAY_MSG (%v), got %v", + OPTION_RELAY_MSG, code, + ) + } +} + +func TestRelayMsgOptionsFromBytes(t *testing.T) { + opts, err := OptionsFromBytes([]byte{ + 0, 9, // option: relay message + 0, 10, // relayed message length + 1, // SOLICIT + 0xaa, 0xbb, 0xcc, // transaction ID + 0, 8, // option: elapsed time + 0, 2, // option length + 0, 0, // option value + }) + if err != nil { + t.Fatal(err) + } + if len(opts) != 1 { + t.Fatalf("Invalid number of options. Expected 1, got %v", len(opts)) + } + opt := opts[0] + if code := opt.Code(); code != OPTION_RELAY_MSG { + t.Fatalf("Invalid option code. Expected OPTION_RELAY_MSG (%v), got %v", + OPTION_RELAY_MSG, code, + ) + } +} |