forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_challenge_frame_test.go
48 lines (41 loc) · 1.41 KB
/
path_challenge_frame_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
package wire
import (
"bytes"
"io"
"github.com/boisjacques/qed/internal/protocol"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("PATH_CHALLENGE frame", func() {
Context("when parsing", func() {
It("accepts sample frame", func() {
b := bytes.NewReader([]byte{0x1a, 1, 2, 3, 4, 5, 6, 7, 8})
f, err := parsePathChallengeFrame(b, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
Expect(b.Len()).To(BeZero())
Expect(f.Data).To(Equal([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
})
It("errors on EOFs", func() {
data := []byte{0x1a, 1, 2, 3, 4, 5, 6, 7, 8}
_, err := parsePathChallengeFrame(bytes.NewReader(data), versionIETFFrames)
Expect(err).NotTo(HaveOccurred())
for i := range data {
_, err := parsePathChallengeFrame(bytes.NewReader(data[0:i]), versionIETFFrames)
Expect(err).To(MatchError(io.EOF))
}
})
})
Context("when writing", func() {
It("writes a sample frame", func() {
b := &bytes.Buffer{}
frame := PathChallengeFrame{Data: [8]byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}}
err := frame.Write(b, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x1a, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}))
})
It("has the correct min length", func() {
frame := PathChallengeFrame{}
Expect(frame.Length(protocol.VersionWhatever)).To(Equal(protocol.ByteCount(9)))
})
})
})