forked from pion/sctp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunk_abort_test.go
57 lines (51 loc) · 1.57 KB
/
chunk_abort_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
package sctp
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAbortChunk(t *testing.T) {
t.Run("One error cause", func(t *testing.T) {
abort1 := &chunkAbort{
errorCauses: []errorCause{&errorCauseProtocolViolation{
errorCauseHeader: errorCauseHeader{code: protocolViolation},
}},
}
bytes, err := abort1.marshal()
assert.NoError(t, err, "should succeed")
abort2 := &chunkAbort{}
err = abort2.unmarshal(bytes)
assert.NoError(t, err, "should succeed")
assert.Equal(t, 1, len(abort2.errorCauses), "should have only one cause")
assert.Equal(t,
abort1.errorCauses[0].errorCauseCode(),
abort2.errorCauses[0].errorCauseCode(),
"errorCause code should match")
})
t.Run("Many error causes", func(t *testing.T) {
abort1 := &chunkAbort{
errorCauses: []errorCause{
&errorCauseProtocolViolation{
errorCauseHeader: errorCauseHeader{code: invalidMandatoryParameter},
},
&errorCauseProtocolViolation{
errorCauseHeader: errorCauseHeader{code: unrecognizedChunkType},
},
&errorCauseProtocolViolation{
errorCauseHeader: errorCauseHeader{code: protocolViolation},
},
},
}
bytes, err := abort1.marshal()
assert.NoError(t, err, "should succeed")
abort2 := &chunkAbort{}
err = abort2.unmarshal(bytes)
assert.NoError(t, err, "should succeed")
assert.Equal(t, 3, len(abort2.errorCauses), "should have only one cause")
for i, errorCause := range abort1.errorCauses {
assert.Equal(t,
errorCause.errorCauseCode(),
abort2.errorCauses[i].errorCauseCode(),
"errorCause code should match")
}
})
}