diff options
Diffstat (limited to 'dhcpv6/duid_test.go')
-rw-r--r-- | dhcpv6/duid_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/dhcpv6/duid_test.go b/dhcpv6/duid_test.go new file mode 100644 index 0000000..23ce709 --- /dev/null +++ b/dhcpv6/duid_test.go @@ -0,0 +1,40 @@ +package dhcpv6 + +import ( + "bytes" + "testing" +) + +func TestDuidUuid(t *testing.T) { + buf := []byte{ + 0x00, 0x04, // type + 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09, // uuid + } + duid, err := DuidFromBytes(buf) + if err != nil { + t.Fatal(err) + } + if dt := duid.Type; dt != DUID_UUID { + t.Fatalf("Invalid Preferred Lifetime. Expected 4, got %d", dt) + } + if uuid := duid.Uuid; !bytes.Equal(uuid, buf[2:]) { + t.Fatalf("Invalid UUID. Expected %v, got %v", buf[2:], uuid) + } + if mac := duid.LinkLayerAddr; mac != nil { + t.Fatalf("Invalid MAC. Expected nil, got %v", mac) + } +} + +func TestDuidUuidToBytes(t *testing.T) { + uuid := []byte{0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09} + expected := []byte{00, 04} + expected = append(expected, uuid...) + duid := Duid{ + Type: DUID_UUID, + Uuid: uuid, + } + toBytes := duid.ToBytes() + if !bytes.Equal(toBytes, expected) { + t.Fatalf("Invalid ToBytes result. Expected %v, got %v", expected, toBytes) + } +} |