github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/internal/wire/retire_connection_id_frame_test.go (about) 1 package wire 2 3 import ( 4 "io" 5 6 "github.com/metacubex/quic-go/internal/protocol" 7 8 . "github.com/onsi/ginkgo/v2" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("NEW_CONNECTION_ID frame", func() { 13 Context("when parsing", func() { 14 It("accepts a sample frame", func() { 15 data := encodeVarInt(0xdeadbeef) // sequence number 16 frame, l, err := parseRetireConnectionIDFrame(data, protocol.Version1) 17 Expect(err).ToNot(HaveOccurred()) 18 Expect(frame.SequenceNumber).To(Equal(uint64(0xdeadbeef))) 19 Expect(l).To(Equal(len(data))) 20 }) 21 22 It("errors on EOFs", func() { 23 data := encodeVarInt(0xdeadbeef) // sequence number 24 _, l, err := parseRetireConnectionIDFrame(data, protocol.Version1) 25 Expect(err).NotTo(HaveOccurred()) 26 Expect(l).To(Equal(len(data))) 27 for i := range data { 28 _, _, err := parseRetireConnectionIDFrame(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 })