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