Debian Codegraph @

chunk_shutdown_test.go

raw
1 // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package sctp
5
6 import (
7 "testing"
8
9 "github.com/stretchr/testify/assert"
10 )
11
12 func TestChunkShutdown_Success(t *testing.T) {
13 tt := []struct {
14 binary []byte
15 }{
16 {[]byte{0x07, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56, 0x78}},
17 }
18
19 for i, tc := range tt {
20 actual := &chunkShutdown{}
21 err := actual.unmarshal(tc.binary)
22 assert.NoErrorf(t, err, "failed to unmarshal #%d: %v", i)
23
24 b, err := actual.marshal()
25 assert.NoError(t, err)
26 assert.Equalf(t, tc.binary, b, "test %d not equal", i)
27 }
28 }
29
30 func TestChunkShutdown_Failure(t *testing.T) {
31 tt := []struct {
32 name string
33 binary []byte
34 }{
35 {"length too short", []byte{0x07, 0x00, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78}},
36 {"length too long", []byte{0x07, 0x00, 0x00, 0x09, 0x12, 0x34, 0x56, 0x78}},
37 {"payload too short", []byte{0x07, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56}},
38 {"payload too long", []byte{0x07, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56, 0x78, 0x9f}},
39 {"invalid type", []byte{0x08, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56, 0x78}},
40 }
41
42 for i, tc := range tt {
43 actual := &chunkShutdown{}
44 err := actual.unmarshal(tc.binary)
45 assert.Errorf(t, err, "expected unmarshal #%d: '%s' to fail.", i, tc.name)
46 }
47 }