github.com/MerlinKodo/quic-go@v0.39.2/internal/wire/max_data_frame_test.go (about)

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