mirror of
https://github.com/gortc/stun.git
synced 2025-09-26 20:41:36 +08:00
errors: improve coverage
This commit is contained in:
32
errors_test.go
Normal file
32
errors_test.go
Normal file
@@ -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")
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user