github.com/tumi8/quic-go@v0.37.4-tum/noninternal/wire/stream_data_blocked_frame_test.go (about) 1 package wire 2 3 import ( 4 "bytes" 5 "io" 6 7 "github.com/tumi8/quic-go/noninternal/protocol" 8 "github.com/tumi8/quic-go/quicvarint" 9 10 . "github.com/onsi/ginkgo/v2" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("STREAM_DATA_BLOCKED frame", func() { 15 Context("parsing", func() { 16 It("accepts sample frame", func() { 17 data := encodeVarInt(0xdeadbeef) // stream ID 18 data = append(data, encodeVarInt(0xdecafbad)...) // offset 19 b := bytes.NewReader(data) 20 frame, err := parseStreamDataBlockedFrame(b, protocol.Version1) 21 Expect(err).ToNot(HaveOccurred()) 22 Expect(frame.StreamID).To(Equal(protocol.StreamID(0xdeadbeef))) 23 Expect(frame.MaximumStreamData).To(Equal(protocol.ByteCount(0xdecafbad))) 24 Expect(b.Len()).To(BeZero()) 25 }) 26 27 It("errors on EOFs", func() { 28 data := encodeVarInt(0xdeadbeef) 29 data = append(data, encodeVarInt(0xc0010ff)...) 30 _, err := parseStreamDataBlockedFrame(bytes.NewReader(data), protocol.Version1) 31 Expect(err).NotTo(HaveOccurred()) 32 for i := range data { 33 _, err := parseStreamDataBlockedFrame(bytes.NewReader(data[:i]), protocol.Version1) 34 Expect(err).To(MatchError(io.EOF)) 35 } 36 }) 37 }) 38 39 Context("writing", func() { 40 It("has proper min length", func() { 41 f := &StreamDataBlockedFrame{ 42 StreamID: 0x1337, 43 MaximumStreamData: 0xdeadbeef, 44 } 45 Expect(f.Length(0)).To(Equal(1 + quicvarint.Len(0x1337) + quicvarint.Len(0xdeadbeef))) 46 }) 47 48 It("writes a sample frame", func() { 49 f := &StreamDataBlockedFrame{ 50 StreamID: 0xdecafbad, 51 MaximumStreamData: 0x1337, 52 } 53 b, err := f.Append(nil, protocol.Version1) 54 Expect(err).ToNot(HaveOccurred()) 55 expected := []byte{streamDataBlockedFrameType} 56 expected = append(expected, encodeVarInt(uint64(f.StreamID))...) 57 expected = append(expected, encodeVarInt(uint64(f.MaximumStreamData))...) 58 Expect(b).To(Equal(expected)) 59 }) 60 }) 61 })