| 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 testChunkReconfigResponce() []byte { |
| 13 |
return []byte{0x0, 0x10, 0x0, 0xc, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1} |
| 14 |
} |
| 15 |
|
| 16 |
func TestParamReconfigResponse_Success(t *testing.T) { |
| 17 |
tt := []struct { |
| 18 |
binary []byte |
| 19 |
parsed *paramReconfigResponse |
| 20 |
}{ |
| 21 |
{ |
| 22 |
testChunkReconfigResponce(), |
| 23 |
¶mReconfigResponse{ |
| 24 |
paramHeader: paramHeader{ |
| 25 |
typ: reconfigResp, |
| 26 |
len: 12, |
| 27 |
raw: testChunkReconfigResponce()[4:], |
| 28 |
}, |
| 29 |
reconfigResponseSequenceNumber: 1, |
| 30 |
result: reconfigResultSuccessPerformed, |
| 31 |
}, |
| 32 |
}, |
| 33 |
} |
| 34 |
|
| 35 |
for i, tc := range tt { |
| 36 |
actual := ¶mReconfigResponse{} |
| 37 |
_, err := actual.unmarshal(tc.binary) |
| 38 |
assert.NoErrorf(t, err, "failed to unmarshal #%d: %v", i) |
| 39 |
assert.Equal(t, tc.parsed, actual) |
| 40 |
|
| 41 |
b, err := actual.marshal() |
| 42 |
assert.NoErrorf(t, err, "failed to marshal #%d: %v", i) |
| 43 |
assert.Equal(t, tc.binary, b) |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
func TestParamReconfigResponse_Failure(t *testing.T) { |
| 48 |
tt := []struct { |
| 49 |
name string |
| 50 |
binary []byte |
| 51 |
}{ |
| 52 |
{"packet too short", testChunkReconfigParamA()[:8]}, |
| 53 |
{"param too short", []byte{0x0, 0x10, 0x0, 0x4}}, |
| 54 |
} |
| 55 |
|
| 56 |
for i, tc := range tt { |
| 57 |
actual := ¶mReconfigResponse{} |
| 58 |
_, err := actual.unmarshal(tc.binary) |
| 59 |
assert.Errorf(t, err, "expected unmarshal #%d: '%s' to fail.", i, tc.name) |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
func TestReconfigResultStringer(t *testing.T) { |
| 64 |
tt := []struct { |
| 65 |
result reconfigResult |
| 66 |
expected string |
| 67 |
}{ |
| 68 |
{reconfigResultSuccessNOP, "0: Success - Nothing to do"}, |
| 69 |
{reconfigResultSuccessPerformed, "1: Success - Performed"}, |
| 70 |
{reconfigResultDenied, "2: Denied"}, |
| 71 |
{reconfigResultErrorWrongSSN, "3: Error - Wrong SSN"}, |
| 72 |
{reconfigResultErrorRequestAlreadyInProgress, "4: Error - Request already in progress"}, |
| 73 |
{reconfigResultErrorBadSequenceNumber, "5: Error - Bad Sequence Number"}, |
| 74 |
{reconfigResultInProgress, "6: In progress"}, |
| 75 |
} |
| 76 |
|
| 77 |
for i, tc := range tt { |
| 78 |
actual := tc.result.String() |
| 79 |
assert.Equalf(t, tc.expected, actual, "Test case %d", i) |
| 80 |
} |
| 81 |
} |