github.com/quic-go/quic-go@v0.44.0/internal/wire/path_challenge_frame_test.go (about)

     1  package wire
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/quic-go/quic-go/internal/protocol"
     7  
     8  	. "github.com/onsi/ginkgo/v2"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("PATH_CHALLENGE frame", func() {
    13  	Context("when parsing", func() {
    14  		It("accepts sample frame", func() {
    15  			b := []byte{1, 2, 3, 4, 5, 6, 7, 8}
    16  			f, l, err := parsePathChallengeFrame(b, protocol.Version1)
    17  			Expect(err).ToNot(HaveOccurred())
    18  			Expect(f.Data).To(Equal([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
    19  			Expect(l).To(Equal(len(b)))
    20  		})
    21  
    22  		It("errors on EOFs", func() {
    23  			data := []byte{1, 2, 3, 4, 5, 6, 7, 8}
    24  			_, l, err := parsePathChallengeFrame(data, protocol.Version1)
    25  			Expect(err).ToNot(HaveOccurred())
    26  			Expect(l).To(Equal(len(data)))
    27  			for i := range data {
    28  				_, _, err := parsePathChallengeFrame(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 := PathChallengeFrame{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{pathChallengeFrameType, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}))
    40  		})
    41  
    42  		It("has the correct length", func() {
    43  			frame := PathChallengeFrame{}
    44  			Expect(frame.Length(protocol.Version1)).To(Equal(protocol.ByteCount(9)))
    45  		})
    46  	})
    47  })