-
Notifications
You must be signed in to change notification settings - Fork 79
/
chunk_shutdown_test.go
53 lines (45 loc) · 1.3 KB
/
chunk_shutdown_test.go
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
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package sctp
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestChunkShutdown_Success(t *testing.T) {
tt := []struct {
binary []byte
}{
{[]byte{0x07, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56, 0x78}},
}
for i, tc := range tt {
actual := &chunkShutdown{}
err := actual.unmarshal(tc.binary)
if err != nil {
t.Fatalf("failed to unmarshal #%d: %v", i, err)
}
b, err := actual.marshal()
if err != nil {
t.Fatalf("failed to marshal: %v", err)
}
assert.Equal(t, tc.binary, b, "test %d not equal", i)
}
}
func TestChunkShutdown_Failure(t *testing.T) {
tt := []struct {
name string
binary []byte
}{
{"length too short", []byte{0x07, 0x00, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78}},
{"length too long", []byte{0x07, 0x00, 0x00, 0x09, 0x12, 0x34, 0x56, 0x78}},
{"payload too short", []byte{0x07, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56}},
{"payload too long", []byte{0x07, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56, 0x78, 0x9f}},
{"invalid type", []byte{0x08, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56, 0x78}},
}
for i, tc := range tt {
actual := &chunkShutdown{}
err := actual.unmarshal(tc.binary)
if err == nil {
t.Errorf("expected unmarshal #%d: '%s' to fail.", i, tc.name)
}
}
}