42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package tlv
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestRouterIDFailZeros(t *testing.T) {
|
|
zeros := [10]byte{}
|
|
if _, _, err := RouterIDFromBytes(zeros[:]); err != ErrRouterIDZeros {
|
|
t.Error("RouterIDFromBytes should fail with ErrRouterIDZeros")
|
|
}
|
|
}
|
|
|
|
func TestRouterIDFailOnes(t *testing.T) {
|
|
ones := [10]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
|
|
if _, _, err := RouterIDFromBytes(ones[:]); err != ErrRouterIDOnes {
|
|
t.Error("RouterIDFromBytes should fail with ErrRouterIDOnes")
|
|
}
|
|
}
|
|
|
|
func TestRouterIDFailLength(t *testing.T) {
|
|
testbytes := [300]byte{}
|
|
for i := 0; i <= len(testbytes); i++ {
|
|
_, _, err := RouterIDFromBytes(testbytes[:i])
|
|
l, isErrRouterIDLength := err.(ErrTLVLength)
|
|
|
|
switch {
|
|
case i >= 10:
|
|
if isErrRouterIDLength {
|
|
t.Error("RouterIDFromBytes returns ErrRouterIDLength for correct length data")
|
|
}
|
|
default:
|
|
if l.l != i {
|
|
t.Errorf("RouterIDFromBytes returns wrong length %d, expected %d", l, i)
|
|
}
|
|
if !isErrRouterIDLength {
|
|
t.Errorf("RouterIDFromBytes returns wrong error for packet of wrong length %d", i)
|
|
}
|
|
}
|
|
}
|
|
}
|