github.com/daeuniverse/quic-go@v0.0.0-20240413031024-943f218e0810/internal/wire/data_blocked_frame_test.go (about)

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