-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy patherrors_test.go
More file actions
28 lines (24 loc) · 847 Bytes
/
errors_test.go
File metadata and controls
28 lines (24 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package stun
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDecodeErr_IsInvalidCookie(t *testing.T) {
m := new(Message)
m.WriteHeader()
decoded := new(Message)
m.Raw[4] = 55
_, err := decoded.Write(m.Raw)
assert.Error(t, err, "should error")
expected := "BadFormat for message/cookie: " +
"3712a442 is invalid magic cookie (should be 2112a442)"
assert.Equal(t, expected, err.Error(), "error message mismatch")
var dErr *DecodeErr
assert.True(t, errors.As(err, &dErr), "not decode error")
assert.True(t, dErr.IsInvalidCookie(), "IsInvalidCookie = false, should be true")
assert.True(t, dErr.IsPlaceChildren("cookie"), "bad children")
assert.True(t, dErr.IsPlaceParent("message"), "bad parent")
}