From fd9ea0a5a190e35788bce07a7266b4330ff13df4 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Feb 2017 13:11:44 +0300 Subject: [PATCH] errors: improve coverage --- errors_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 errors_test.go diff --git a/errors_test.go b/errors_test.go new file mode 100644 index 0000000..289bff7 --- /dev/null +++ b/errors_test.go @@ -0,0 +1,32 @@ +package stun + +import "testing" + +func TestDecodeErr_IsInvalidCookie(t *testing.T) { + m := new(Message) + m.WriteHeader() + decoded := new(Message) + m.Raw[4] = 55 + _, err := decoded.Write(m.Raw) + if err == nil { + t.Fatal("should error") + } + expected := "BadFormat for message/cookie: " + + "3712a442 is invalid magic cookie (should be 2112a442)" + if err.Error() != expected { + t.Error(err, "!=", expected) + } + dErr, ok := err.(*DecodeErr) + if !ok { + t.Error("not decode error") + } + if !dErr.IsInvalidCookie() { + t.Error("IsInvalidCookie = false, should be true") + } + if !dErr.IsPlaceChildren("cookie") { + t.Error("bad children") + } + if !dErr.IsPlaceParent("message") { + t.Error("bad parent") + } +}