File: paramheader_test.go

package info (click to toggle)
golang-github-pion-sctp 1.8.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports, sid, trixie
  • size: 888 kB
  • sloc: makefile: 13
file content (61 lines) | stat: -rw-r--r-- 1,264 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package sctp

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func testParamHeader() []byte {
	return []byte{0x0, 0x1, 0x0, 0x4}
}

func TestParamHeader_Success(t *testing.T) {
	tt := []struct {
		binary []byte
		parsed *paramHeader
	}{
		{
			testParamHeader(),
			&paramHeader{
				typ: heartbeatInfo,
				len: 4,
				raw: []byte{},
			},
		},
	}

	for i, tc := range tt {
		actual := &paramHeader{}
		err := actual.unmarshal(tc.binary)
		if err != nil {
			t.Errorf("failed to unmarshal #%d: %v", i, err)
		}
		assert.Equal(t, tc.parsed, actual)
		b, err := actual.marshal()
		if err != nil {
			t.Errorf("failed to marshal: %v", err)
		}
		assert.Equal(t, tc.binary, b)
	}
}

func TestParamHeaderUnmarshal_Failure(t *testing.T) {
	tt := []struct {
		name   string
		binary []byte
	}{
		{"header too short", testParamHeader()[:2]},
		// {"wrong param type", []byte{0x0, 0x0, 0x0, 0x4}}, // Not possible to fail parseParamType atm.
		{"reported length below header length", []byte{0x0, 0xd, 0x0, 0x3}},
		{"wrong reported length", testChunkReconfigParamA()[:4]},
	}

	for i, tc := range tt {
		actual := &paramHeader{}
		err := actual.unmarshal(tc.binary)
		if err == nil {
			t.Errorf("expected unmarshal #%d: '%s' to fail.", i, tc.name)
		}
	}
}