32 lines
523 B
Go
32 lines
523 B
Go
package iptools
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestHardwareMacMarshalling(t *testing.T) {
|
|
macString := "b8:27:eb:b6:a1:a7"
|
|
mac := HardwareAddress([]byte{0xb8, 0x27, 0xeb, 0xb6, 0xa1, 0xa7})
|
|
|
|
b, err := mac.MarshalText()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
s := string(b)
|
|
if s != macString {
|
|
t.Fatalf("have %s, want %s", s, macString)
|
|
}
|
|
|
|
mac2 := &HardwareAddress{}
|
|
err = mac2.UnmarshalText(b)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !bytes.Equal(*mac2, mac) {
|
|
t.Fatalf("have %x, want %x", *mac2, mac)
|
|
}
|
|
}
|