File: errors_test.go

package info (click to toggle)
golang-github-pion-stun 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 868 kB
  • sloc: sh: 50; makefile: 40
file content (38 lines) | stat: -rw-r--r-- 826 bytes parent folder | download | duplicates (2)
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
29
30
31
32
33
34
35
36
37
38
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package stun

import (
	"errors"
	"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)
	}
	var dErr *DecodeErr
	if !errors.As(err, &dErr) {
		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")
	}
}