-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
data_blocked_frame_test.go
53 lines (46 loc) · 1.52 KB
/
data_blocked_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
49
50
51
52
53
package wire
import (
"bytes"
"io"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/quicvarint"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("DATA_BLOCKED frame", func() {
Context("when parsing", func() {
It("accepts sample frame", func() {
data := []byte{0x14}
data = append(data, encodeVarInt(0x12345678)...)
b := bytes.NewReader(data)
frame, err := parseDataBlockedFrame(b, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(frame.MaximumData).To(Equal(protocol.ByteCount(0x12345678)))
Expect(b.Len()).To(BeZero())
})
It("errors on EOFs", func() {
data := []byte{0x14}
data = append(data, encodeVarInt(0x12345678)...)
_, err := parseDataBlockedFrame(bytes.NewReader(data), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
for i := range data {
_, err := parseDataBlockedFrame(bytes.NewReader(data[:i]), protocol.Version1)
Expect(err).To(MatchError(io.EOF))
}
})
})
Context("when writing", func() {
It("writes a sample frame", func() {
frame := DataBlockedFrame{MaximumData: 0xdeadbeef}
b, err := frame.Append(nil, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
expected := []byte{0x14}
expected = append(expected, encodeVarInt(0xdeadbeef)...)
Expect(b).To(Equal(expected))
})
It("has the correct min length", func() {
frame := DataBlockedFrame{MaximumData: 0x12345}
Expect(frame.Length(protocol.Version1)).To(Equal(1 + quicvarint.Len(0x12345)))
})
})
})