github.com/danielpfeifer02/quic-go-prio-packs@v0.41.0-28/internal/wire/retire_connection_id_frame_test.go (about)

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