This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunk_error_test.go
63 lines (51 loc) · 2 KB
/
chunk_error_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
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package sctp
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestChunkErrorUnrecognizedChunkType(t *testing.T) {
const chunkFlags byte = 0x00
orgUnrecognizedChunk := []byte{0xc0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x3}
rawIn := append([]byte{byte(ctError), chunkFlags, 0x00, 0x10, 0x00, 0x06, 0x00, 0x0c}, orgUnrecognizedChunk...)
t.Run("unmarshal", func(t *testing.T) {
c := &chunkError{}
err := c.unmarshal(rawIn)
assert.Nil(t, err, "unmarshal should succeed")
assert.Equal(t, ctError, c.typ, "chunk type should be ERROR")
assert.Equal(t, 1, len(c.errorCauses), "there should be on errorCause")
ec := c.errorCauses[0]
assert.Equal(t, unrecognizedChunkType, ec.errorCauseCode(), "cause code should be unrecognizedChunkType")
ecUnrecognizedChunkType, ok := ec.(*errorCauseUnrecognizedChunkType)
assert.True(t, ok)
unrecognizedChunk := ecUnrecognizedChunkType.unrecognizedChunk
assert.True(t, reflect.DeepEqual(unrecognizedChunk, orgUnrecognizedChunk), "should have valid unrecognizedChunk")
})
t.Run("marshal", func(t *testing.T) {
ecUnrecognizedChunkType := &errorCauseUnrecognizedChunkType{
unrecognizedChunk: orgUnrecognizedChunk,
}
ec := &chunkError{
errorCauses: []errorCause{
errorCause(ecUnrecognizedChunkType),
},
}
raw, err := ec.marshal()
assert.Nil(t, err, "marshal should succeed")
assert.True(t, reflect.DeepEqual(raw, rawIn), "unexpected serialization result")
})
t.Run("marshal with cause value being nil", func(t *testing.T) {
expected := []byte{byte(ctError), chunkFlags, 0x00, 0x08, 0x00, 0x06, 0x00, 0x04}
ecUnrecognizedChunkType := &errorCauseUnrecognizedChunkType{}
ec := &chunkError{
errorCauses: []errorCause{
errorCause(ecUnrecognizedChunkType),
},
}
raw, err := ec.marshal()
assert.Nil(t, err, "marshal should succeed")
assert.True(t, reflect.DeepEqual(raw, expected), "unexpected serialization result")
})
}