github.com/danielpfeifer02/quic-go-prio-packs@v0.41.0-28/internal/wire/path_response_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("PATH_RESPONSE frame", func() {
    14  	Context("when parsing", func() {
    15  		It("accepts sample frame", func() {
    16  			b := bytes.NewReader([]byte{1, 2, 3, 4, 5, 6, 7, 8})
    17  			f, err := parsePathResponseFrame(b, protocol.Version1)
    18  			Expect(err).ToNot(HaveOccurred())
    19  			Expect(b.Len()).To(BeZero())
    20  			Expect(f.Data).To(Equal([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
    21  		})
    22  
    23  		It("errors on EOFs", func() {
    24  			data := []byte{1, 2, 3, 4, 5, 6, 7, 8}
    25  			_, err := parsePathResponseFrame(bytes.NewReader(data), protocol.Version1)
    26  			Expect(err).NotTo(HaveOccurred())
    27  			for i := range data {
    28  				_, err := parsePathResponseFrame(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 := PathResponseFrame{Data: [8]byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}}
    37  			b, err := frame.Append(nil, protocol.Version1)
    38  			Expect(err).ToNot(HaveOccurred())
    39  			Expect(b).To(Equal([]byte{pathResponseFrameType, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}))
    40  		})
    41  
    42  		It("has the correct length", func() {
    43  			frame := PathResponseFrame{}
    44  			Expect(frame.Length(protocol.Version1)).To(Equal(protocol.ByteCount(9)))
    45  		})
    46  	})
    47  })