forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclose_reason_test.go
70 lines (61 loc) · 1.85 KB
/
close_reason_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
package logging
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Close Reason", func() {
checkNotApplicationError := func(r CloseReason) {
_, _, ok := r.ApplicationError()
Expect(ok).To(BeFalse())
}
checkNotTransportError := func(r CloseReason) {
_, _, ok := r.TransportError()
Expect(ok).To(BeFalse())
}
checkNotStatelessReset := func(r CloseReason) {
_, ok := r.StatelessReset()
ExpectWithOffset(1, ok).To(BeFalse())
}
checkNotTimeout := func(r CloseReason) {
_, ok := r.Timeout()
ExpectWithOffset(1, ok).To(BeFalse())
}
It("application errors", func() {
r := NewApplicationCloseReason(1337, true)
errorCode, remote, ok := r.ApplicationError()
Expect(ok).To(BeTrue())
Expect(remote).To(BeTrue())
Expect(errorCode).To(Equal(ApplicationError(1337)))
checkNotTransportError(r)
checkNotStatelessReset(r)
checkNotTimeout(r)
})
It("transport errors", func() {
r := NewTransportCloseReason(1337, true)
errorCode, remote, ok := r.TransportError()
Expect(ok).To(BeTrue())
Expect(remote).To(BeTrue())
Expect(errorCode).To(Equal(TransportError(1337)))
checkNotApplicationError(r)
checkNotStatelessReset(r)
checkNotTimeout(r)
})
It("transport errors", func() {
r := NewTimeoutCloseReason(TimeoutReasonIdle)
timeout, ok := r.Timeout()
Expect(ok).To(BeTrue())
Expect(timeout).To(Equal(TimeoutReasonIdle))
checkNotApplicationError(r)
checkNotTransportError(r)
checkNotStatelessReset(r)
})
It("stateless resets", func() {
r := NewStatelessResetCloseReason(StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})
token, ok := r.StatelessReset()
Expect(ok).To(BeTrue())
Expect(token).To(Equal(StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}))
checkNotApplicationError(r)
checkNotTransportError(r)
checkNotTimeout(r)
})
})