Debian Codegraph @

param_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 TestBuildParam_Success(t *testing.T) {
13 tt := []struct {
14 binary []byte
15 }{
16 {testChunkReconfigParamA()},
17 }
18
19 for i, tc := range tt {
20 pType, err := parseParamType(tc.binary)
21 assert.NoErrorf(t, err, "failed to parse param type #%d", i)
22
23 p, err := buildParam(pType, tc.binary)
24 assert.NoErrorf(t, err, "failed to unmarshal #%d", i)
25
26 b, err := p.marshal()
27 assert.NoErrorf(t, err, "failed to marshal #%d", i)
28 assert.Equal(t, tc.binary, b)
29 }
30 }
31
32 func TestBuildParam_Failure(t *testing.T) {
33 tt := []struct {
34 name string
35 binary []byte
36 }{
37 {"invalid ParamType", []byte{0x0, 0x0}},
38 {"build failure", testChunkReconfigParamA()[:8]},
39 }
40
41 for i, tc := range tt {
42 pType, err := parseParamType(tc.binary)
43 assert.NoErrorf(t, err, "failed to parse param type #%d", i)
44
45 _, err = buildParam(pType, tc.binary)
46 assert.Errorf(t, err, "expected buildParam #%d: '%s' to fail.", i, tc.name)
47 }
48 }