github.com/quic-go/quic-go@v0.44.0/internal/wire/stream_data_blocked_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("STREAM_DATA_BLOCKED frame", func() {
    14  	Context("parsing", func() {
    15  		It("accepts sample frame", func() {
    16  			data := encodeVarInt(0xdeadbeef)                 // stream ID
    17  			data = append(data, encodeVarInt(0xdecafbad)...) // offset
    18  			frame, l, err := parseStreamDataBlockedFrame(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(0xdecafbad)))
    22  			Expect(l).To(Equal(len(data)))
    23  		})
    24  
    25  		It("errors on EOFs", func() {
    26  			data := encodeVarInt(0xdeadbeef)
    27  			data = append(data, encodeVarInt(0xc0010ff)...)
    28  			_, l, err := parseStreamDataBlockedFrame(data, protocol.Version1)
    29  			Expect(err).NotTo(HaveOccurred())
    30  			Expect(l).To(Equal(len(data)))
    31  			for i := range data {
    32  				_, _, err := parseStreamDataBlockedFrame(data[:i], protocol.Version1)
    33  				Expect(err).To(MatchError(io.EOF))
    34  			}
    35  		})
    36  	})
    37  
    38  	Context("writing", func() {
    39  		It("has proper min length", func() {
    40  			f := &StreamDataBlockedFrame{
    41  				StreamID:          0x1337,
    42  				MaximumStreamData: 0xdeadbeef,
    43  			}
    44  			Expect(f.Length(0)).To(BeEquivalentTo(1 + quicvarint.Len(0x1337) + quicvarint.Len(0xdeadbeef)))
    45  		})
    46  
    47  		It("writes a sample frame", func() {
    48  			f := &StreamDataBlockedFrame{
    49  				StreamID:          0xdecafbad,
    50  				MaximumStreamData: 0x1337,
    51  			}
    52  			b, err := f.Append(nil, protocol.Version1)
    53  			Expect(err).ToNot(HaveOccurred())
    54  			expected := []byte{streamDataBlockedFrameType}
    55  			expected = append(expected, encodeVarInt(uint64(f.StreamID))...)
    56  			expected = append(expected, encodeVarInt(uint64(f.MaximumStreamData))...)
    57  			Expect(b).To(Equal(expected))
    58  		})
    59  	})
    60  })