-
Notifications
You must be signed in to change notification settings - Fork 79
/
param_reconfig_response_test.go
86 lines (76 loc) · 2.1 KB
/
param_reconfig_response_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package sctp
import (
"testing"
"github.com/stretchr/testify/assert"
)
func testChunkReconfigResponce() []byte {
return []byte{0x0, 0x10, 0x0, 0xc, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1}
}
func TestParamReconfigResponse_Success(t *testing.T) {
tt := []struct {
binary []byte
parsed *paramReconfigResponse
}{
{
testChunkReconfigResponce(),
¶mReconfigResponse{
paramHeader: paramHeader{
typ: reconfigResp,
len: 12,
raw: testChunkReconfigResponce()[4:],
},
reconfigResponseSequenceNumber: 1,
result: reconfigResultSuccessPerformed,
},
},
}
for i, tc := range tt {
actual := ¶mReconfigResponse{}
_, err := actual.unmarshal(tc.binary)
if err != nil {
t.Fatalf("failed to unmarshal #%d: %v", i, err)
}
assert.Equal(t, tc.parsed, actual)
b, err := actual.marshal()
if err != nil {
t.Fatalf("failed to marshal: %v", err)
}
assert.Equal(t, tc.binary, b)
}
}
func TestParamReconfigResponse_Failure(t *testing.T) {
tt := []struct {
name string
binary []byte
}{
{"packet too short", testChunkReconfigParamA()[:8]},
{"param too short", []byte{0x0, 0x10, 0x0, 0x4}},
}
for i, tc := range tt {
actual := ¶mReconfigResponse{}
_, err := actual.unmarshal(tc.binary)
if err == nil {
t.Errorf("expected unmarshal #%d: '%s' to fail.", i, tc.name)
}
}
}
func TestReconfigResultStringer(t *testing.T) {
tt := []struct {
result reconfigResult
expected string
}{
{reconfigResultSuccessNOP, "0: Success - Nothing to do"},
{reconfigResultSuccessPerformed, "1: Success - Performed"},
{reconfigResultDenied, "2: Denied"},
{reconfigResultErrorWrongSSN, "3: Error - Wrong SSN"},
{reconfigResultErrorRequestAlreadyInProgress, "4: Error - Request already in progress"},
{reconfigResultErrorBadSequenceNumber, "5: Error - Bad Sequence Number"},
{reconfigResultInProgress, "6: In progress"},
}
for i, tc := range tt {
actual := tc.result.String()
assert.Equal(t, tc.expected, actual, "Test case %d", i)
}
}