github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/internal/wire/data_blocked_frame_test.go (about) 1 package wire 2 3 import ( 4 "io" 5 6 "github.com/metacubex/quic-go/internal/protocol" 7 "github.com/metacubex/quic-go/quicvarint" 8 9 . "github.com/onsi/ginkgo/v2" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("DATA_BLOCKED frame", func() { 14 Context("when parsing", func() { 15 It("accepts sample frame", func() { 16 data := encodeVarInt(0x12345678) 17 frame, l, err := parseDataBlockedFrame(data, protocol.Version1) 18 Expect(err).ToNot(HaveOccurred()) 19 Expect(frame.MaximumData).To(Equal(protocol.ByteCount(0x12345678))) 20 Expect(l).To(Equal(len(data))) 21 }) 22 23 It("errors on EOFs", func() { 24 data := encodeVarInt(0x12345678) 25 _, l, err := parseDataBlockedFrame(data, protocol.Version1) 26 Expect(err).ToNot(HaveOccurred()) 27 Expect(l).To(Equal(len(data))) 28 for i := range data { 29 _, _, err := parseDataBlockedFrame(data[:i], protocol.Version1) 30 Expect(err).To(MatchError(io.EOF)) 31 } 32 }) 33 }) 34 35 Context("when writing", func() { 36 It("writes a sample frame", func() { 37 frame := DataBlockedFrame{MaximumData: 0xdeadbeef} 38 b, err := frame.Append(nil, protocol.Version1) 39 Expect(err).ToNot(HaveOccurred()) 40 expected := []byte{dataBlockedFrameType} 41 expected = append(expected, encodeVarInt(0xdeadbeef)...) 42 Expect(b).To(Equal(expected)) 43 }) 44 45 It("has the correct min length", func() { 46 frame := DataBlockedFrame{MaximumData: 0x12345} 47 Expect(frame.Length(protocol.Version1)).To(BeEquivalentTo(1 + quicvarint.Len(0x12345))) 48 }) 49 }) 50 })