-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathparamtype_test.go
More file actions
86 lines (77 loc) · 2.76 KB
/
paramtype_test.go
File metadata and controls
86 lines (77 loc) · 2.76 KB
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: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package sctp
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseParamType_Success(t *testing.T) {
tt := []struct {
binary []byte
expected paramType
}{
{[]byte{0x0, 0x1}, heartbeatInfo},
{[]byte{0x0, 0xd}, outSSNResetReq},
}
for i, tc := range tt {
pType, err := parseParamType(tc.binary)
assert.NoErrorf(t, err, "failed to parse paramType #%d", i)
assert.Equal(t, tc.expected, pType)
}
}
func TestParseParamType_Failure(t *testing.T) {
tt := []struct {
name string
binary []byte
}{
{"empty packet", []byte{}},
}
for i, tc := range tt {
_, err := parseParamType(tc.binary)
assert.Errorf(t, err, "expected parseParamType #%d: '%s' to fail.", i, tc.name)
}
}
func TestParamType_String(t *testing.T) {
tests := []struct {
name string
in paramType
want string
}{
{"heartbeatInfo", heartbeatInfo, "Heartbeat Info"},
{"ipV4Addr", ipV4Addr, "IPv4 IP"},
{"ipV6Addr", ipV6Addr, "IPv6 IP"},
{"stateCookie", stateCookie, "State Cookie"},
{"unrecognizedParam", unrecognizedParam, "Unrecognized Parameters"},
{"cookiePreservative", cookiePreservative, "Cookie Preservative"},
{"hostNameAddr", hostNameAddr, "Host Name Address"},
{"supportedAddrTypes", supportedAddrTypes, "Supported IP Types"},
{"outSSNResetReq", outSSNResetReq, "Outgoing SSN Reset Request Parameter"},
{"incSSNResetReq", incSSNResetReq, "Incoming SSN Reset Request Parameter"},
{"ssnTSNResetReq", ssnTSNResetReq, "SSN/TSN Reset Request Parameter"},
{"reconfigResp", reconfigResp, "Re-configuration Response Parameter"},
{"addOutStreamsReq", addOutStreamsReq, "Add Outgoing Streams Request Parameter"},
{"addIncStreamsReq", addIncStreamsReq, "Add Incoming Streams Request Parameter"},
{"ecnCapable", ecnCapable, "ECN Capable"},
{"zeroChecksumAcceptable", zeroChecksumAcceptable, "Zero Checksum Acceptable"},
{"random", random, "Random"},
{"chunkList", chunkList, "Chunk List"},
{"reqHMACAlgo", reqHMACAlgo, "Requested HMAC Algorithm Parameter"},
{"padding", padding, "Padding"},
{"supportedExt", supportedExt, "Supported Extensions"},
{"forwardTSNSupp", forwardTSNSupp, "Forward TSN supported"},
{"addIPAddr", addIPAddr, "Add IP Address"},
{"delIPAddr", delIPAddr, "Delete IP Address"},
{"errClauseInd", errClauseInd, "Error Cause Indication"},
{"setPriAddr", setPriAddr, "Set Primary IP"},
{"successInd", successInd, "Success Indication"},
{"adaptLayerInd", adaptLayerInd, "Adaptation Layer Indication"},
{"unknownValue", paramType(0x4242), fmt.Sprintf("Unknown ParamType: %d", 0x4242)},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := tc.in.String()
assert.Equal(t, tc.want, got)
})
}
}