forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors_test.go
37 lines (33 loc) · 1.15 KB
/
errors_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
package quic
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
)
func TestStreamError(t *testing.T) {
require.True(t, errors.Is(
&StreamError{StreamID: 1, ErrorCode: 2, Remote: true},
&StreamError{StreamID: 1, ErrorCode: 2, Remote: true},
))
require.False(t, errors.Is(&StreamError{StreamID: 1}, &StreamError{StreamID: 2}))
require.False(t, errors.Is(&StreamError{StreamID: 1}, &StreamError{StreamID: 2}))
require.Equal(t,
"stream 1 canceled by remote with error code 2",
(&StreamError{StreamID: 1, ErrorCode: 2, Remote: true}).Error(),
)
require.Equal(t,
"stream 42 canceled by local with error code 1337",
(&StreamError{StreamID: 42, ErrorCode: 1337, Remote: false}).Error(),
)
}
func TestDatagramTooLargeError(t *testing.T) {
require.True(t, errors.Is(
&DatagramTooLargeError{MaxDatagramPayloadSize: 1024},
&DatagramTooLargeError{MaxDatagramPayloadSize: 1024},
))
require.False(t, errors.Is(
&DatagramTooLargeError{MaxDatagramPayloadSize: 1024},
&DatagramTooLargeError{MaxDatagramPayloadSize: 1025},
))
require.Equal(t, "DATAGRAM frame too large", (&DatagramTooLargeError{MaxDatagramPayloadSize: 1024}).Error())
}