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