github.com/tumi8/quic-go@v0.37.4-tum/noninternal/wire/max_stream_data_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("MAX_STREAM_DATA frame", func() {
    15  	Context("parsing", func() {
    16  		It("accepts sample frame", func() {
    17  			data := encodeVarInt(0xdeadbeef)                 // Stream ID
    18  			data = append(data, encodeVarInt(0x12345678)...) // Offset
    19  			b := bytes.NewReader(data)
    20  			frame, err := parseMaxStreamDataFrame(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(0x12345678)))
    24  			Expect(b.Len()).To(BeZero())
    25  		})
    26  
    27  		It("errors on EOFs", func() {
    28  			data := encodeVarInt(0xdeadbeef)                 // Stream ID
    29  			data = append(data, encodeVarInt(0x12345678)...) // Offset
    30  			b := bytes.NewReader(data)
    31  			_, err := parseMaxStreamDataFrame(b, protocol.Version1)
    32  			Expect(err).NotTo(HaveOccurred())
    33  			for i := range data {
    34  				_, err := parseMaxStreamDataFrame(bytes.NewReader(data[:i]), protocol.Version1)
    35  				Expect(err).To(MatchError(io.EOF))
    36  			}
    37  		})
    38  	})
    39  
    40  	Context("writing", func() {
    41  		It("has proper length", func() {
    42  			f := &MaxStreamDataFrame{
    43  				StreamID:          0x1337,
    44  				MaximumStreamData: 0xdeadbeef,
    45  			}
    46  			Expect(f.Length(protocol.Version1)).To(Equal(1 + quicvarint.Len(uint64(f.StreamID)) + quicvarint.Len(uint64(f.MaximumStreamData))))
    47  		})
    48  
    49  		It("writes a sample frame", func() {
    50  			f := &MaxStreamDataFrame{
    51  				StreamID:          0xdecafbad,
    52  				MaximumStreamData: 0xdeadbeefcafe42,
    53  			}
    54  			expected := []byte{maxStreamDataFrameType}
    55  			expected = append(expected, encodeVarInt(0xdecafbad)...)
    56  			expected = append(expected, encodeVarInt(0xdeadbeefcafe42)...)
    57  			b, err := f.Append(nil, protocol.Version1)
    58  			Expect(err).ToNot(HaveOccurred())
    59  			Expect(b).To(Equal(expected))
    60  		})
    61  	})
    62  })