github.com/tumi8/quic-go@v0.37.4-tum/noninternal/wire/path_response_frame_test.go (about)

     1  package wire
     2  
     3  import (
     4  	"bytes"
     5  	"io"
     6  
     7  	"github.com/tumi8/quic-go/noninternal/protocol"
     8  	. "github.com/onsi/ginkgo/v2"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("PATH_RESPONSE frame", func() {
    13  	Context("when parsing", func() {
    14  		It("accepts sample frame", func() {
    15  			b := bytes.NewReader([]byte{1, 2, 3, 4, 5, 6, 7, 8})
    16  			f, err := parsePathResponseFrame(b, protocol.Version1)
    17  			Expect(err).ToNot(HaveOccurred())
    18  			Expect(b.Len()).To(BeZero())
    19  			Expect(f.Data).To(Equal([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
    20  		})
    21  
    22  		It("errors on EOFs", func() {
    23  			data := []byte{1, 2, 3, 4, 5, 6, 7, 8}
    24  			_, err := parsePathResponseFrame(bytes.NewReader(data), protocol.Version1)
    25  			Expect(err).NotTo(HaveOccurred())
    26  			for i := range data {
    27  				_, err := parsePathResponseFrame(bytes.NewReader(data[:i]), protocol.Version1)
    28  				Expect(err).To(MatchError(io.EOF))
    29  			}
    30  		})
    31  	})
    32  
    33  	Context("when writing", func() {
    34  		It("writes a sample frame", func() {
    35  			frame := PathResponseFrame{Data: [8]byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}}
    36  			b, err := frame.Append(nil, protocol.Version1)
    37  			Expect(err).ToNot(HaveOccurred())
    38  			Expect(b).To(Equal([]byte{pathResponseFrameType, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}))
    39  		})
    40  
    41  		It("has the correct length", func() {
    42  			frame := PathResponseFrame{}
    43  			Expect(frame.Length(protocol.Version1)).To(Equal(protocol.ByteCount(9)))
    44  		})
    45  	})
    46  })