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

     1  package wire
     2  
     3  import (
     4  	"bytes"
     5  	"io"
     6  
     7  	"github.com/MerlinKodo/quic-go/internal/protocol"
     8  
     9  	. "github.com/onsi/ginkgo/v2"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("PATH_CHALLENGE 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 := parsePathChallengeFrame(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  			b := bytes.NewReader(data)
    26  			_, err := parsePathChallengeFrame(b, protocol.Version1)
    27  			Expect(err).ToNot(HaveOccurred())
    28  			for i := range data {
    29  				_, err := parsePathChallengeFrame(bytes.NewReader(data[:i]), protocol.Version1)
    30  				Expect(err).To(MatchError(io.EOF))
    31  			}
    32  		})
    33  	})
    34  
    35  	Context("when writing", func() {
    36  		It("writes a sample frame", func() {
    37  			frame := PathChallengeFrame{Data: [8]byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}}
    38  			b, err := frame.Append(nil, protocol.Version1)
    39  			Expect(err).ToNot(HaveOccurred())
    40  			Expect(b).To(Equal([]byte{pathChallengeFrameType, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}))
    41  		})
    42  
    43  		It("has the correct length", func() {
    44  			frame := PathChallengeFrame{}
    45  			Expect(frame.Length(protocol.Version1)).To(Equal(protocol.ByteCount(9)))
    46  		})
    47  	})
    48  })