-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
errors_test.go
124 lines (107 loc) · 4.01 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package qerr
import (
"errors"
"net"
"github.com/lucas-clemente/quic-go/internal/protocol"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("QUIC Errors", func() {
Context("Transport Errors", func() {
It("has a string representation", func() {
Expect((&TransportError{
ErrorCode: FlowControlError,
ErrorMessage: "foobar",
}).Error()).To(Equal("FLOW_CONTROL_ERROR: foobar"))
})
It("has a string representation for empty error phrases", func() {
Expect((&TransportError{ErrorCode: FlowControlError}).Error()).To(Equal("FLOW_CONTROL_ERROR"))
})
It("includes the frame type, for errors without a message", func() {
Expect((&TransportError{
ErrorCode: FlowControlError,
FrameType: 0x1337,
}).Error()).To(Equal("FLOW_CONTROL_ERROR (frame type: 0x1337)"))
})
It("includes the frame type, for errors with a message", func() {
Expect((&TransportError{
ErrorCode: FlowControlError,
FrameType: 0x1337,
ErrorMessage: "foobar",
}).Error()).To(Equal("FLOW_CONTROL_ERROR (frame type: 0x1337): foobar"))
})
Context("crypto errors", func() {
It("has a string representation for errors with a message", func() {
err := NewCryptoError(0x42, "foobar")
Expect(err.Error()).To(Equal("CRYPTO_ERROR (0x142): foobar"))
})
It("has a string representation for errors without a message", func() {
err := NewCryptoError(0x2a, "")
Expect(err.Error()).To(Equal("CRYPTO_ERROR (0x12a): tls: bad certificate"))
})
})
})
Context("Application Errors", func() {
It("has a string representation for errors with a message", func() {
Expect((&ApplicationError{
ErrorCode: 0x42,
ErrorMessage: "foobar",
}).Error()).To(Equal("Application error 0x42: foobar"))
})
It("has a string representation for errors without a message", func() {
Expect((&ApplicationError{
ErrorCode: 0x42,
}).Error()).To(Equal("Application error 0x42"))
})
})
Context("timeout errors", func() {
It("handshake timeouts", func() {
//nolint:gosimple // we need to assign to an interface here
var err error
err = &HandshakeTimeoutError{}
nerr, ok := err.(net.Error)
Expect(ok).To(BeTrue())
Expect(nerr.Timeout()).To(BeTrue())
Expect(err.Error()).To(Equal("timeout: handshake did not complete in time"))
})
It("idle timeouts", func() {
//nolint:gosimple // we need to assign to an interface here
var err error
err = &IdleTimeoutError{}
nerr, ok := err.(net.Error)
Expect(ok).To(BeTrue())
Expect(nerr.Timeout()).To(BeTrue())
Expect(err.Error()).To(Equal("timeout: no recent network activity"))
})
})
Context("Version Negotiation errors", func() {
It("has a string representation", func() {
Expect((&VersionNegotiationError{
Ours: []protocol.VersionNumber{2, 3},
Theirs: []protocol.VersionNumber{4, 5, 6},
}).Error()).To(Equal("no compatible QUIC version found (we support [0x2 0x3], server offered [0x4 0x5 0x6])"))
})
})
Context("Stateless Reset errors", func() {
token := protocol.StatelessResetToken{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf}
It("has a string representation", func() {
Expect((&StatelessResetError{Token: token}).Error()).To(Equal("received a stateless reset with token 000102030405060708090a0b0c0d0e0f"))
})
It("is a net.Error", func() {
//nolint:gosimple // we need to assign to an interface here
var err error
err = &StatelessResetError{}
nerr, ok := err.(net.Error)
Expect(ok).To(BeTrue())
Expect(nerr.Timeout()).To(BeFalse())
})
})
It("says that errors are net.ErrClosed errors", func() {
Expect(errors.Is(&TransportError{}, net.ErrClosed)).To(BeTrue())
Expect(errors.Is(&ApplicationError{}, net.ErrClosed)).To(BeTrue())
Expect(errors.Is(&IdleTimeoutError{}, net.ErrClosed)).To(BeTrue())
Expect(errors.Is(&HandshakeTimeoutError{}, net.ErrClosed)).To(BeTrue())
Expect(errors.Is(&StatelessResetError{}, net.ErrClosed)).To(BeTrue())
Expect(errors.Is(&VersionNegotiationError{}, net.ErrClosed)).To(BeTrue())
})
})