1package stun 2 3import "testing" 4 5func TestDecodeErr_IsInvalidCookie(t *testing.T) { 6 m := new(Message) 7 m.WriteHeader() 8 decoded := new(Message) 9 m.Raw[4] = 55 10 _, err := decoded.Write(m.Raw) 11 if err == nil { 12 t.Fatal("should error") 13 } 14 expected := "BadFormat for message/cookie: " + 15 "3712a442 is invalid magic cookie (should be 2112a442)" 16 if err.Error() != expected { 17 t.Error(err, "!=", expected) 18 } 19 dErr, ok := err.(*DecodeErr) 20 if !ok { 21 t.Error("not decode error") 22 } 23 if !dErr.IsInvalidCookie() { 24 t.Error("IsInvalidCookie = false, should be true") 25 } 26 if !dErr.IsPlaceChildren("cookie") { 27 t.Error("bad children") 28 } 29 if !dErr.IsPlaceParent("message") { 30 t.Error("bad parent") 31 } 32} 33