github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/internal/wire/stop_sending_frame_test.go (about) 1 package wire 2 3 import ( 4 "io" 5 6 "github.com/metacubex/quic-go/internal/protocol" 7 "github.com/metacubex/quic-go/internal/qerr" 8 "github.com/metacubex/quic-go/quicvarint" 9 10 . "github.com/onsi/ginkgo/v2" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("STOP_SENDING frame", func() { 15 Context("when parsing", func() { 16 It("parses a sample frame", func() { 17 data := encodeVarInt(0xdecafbad) // stream ID 18 data = append(data, encodeVarInt(0x1337)...) // error code 19 frame, l, err := parseStopSendingFrame(data, protocol.Version1) 20 Expect(err).ToNot(HaveOccurred()) 21 Expect(frame.StreamID).To(Equal(protocol.StreamID(0xdecafbad))) 22 Expect(frame.ErrorCode).To(Equal(qerr.StreamErrorCode(0x1337))) 23 Expect(l).To(Equal(len(data))) 24 }) 25 26 It("errors on EOFs", func() { 27 data := encodeVarInt(0xdecafbad) // stream ID 28 data = append(data, encodeVarInt(0x123456)...) // error code 29 _, l, err := parseStopSendingFrame(data, protocol.Version1) 30 Expect(err).NotTo(HaveOccurred()) 31 Expect(l).To(Equal(len(data))) 32 for i := range data { 33 _, _, err := parseStopSendingFrame(data[:i], protocol.Version1) 34 Expect(err).To(MatchError(io.EOF)) 35 } 36 }) 37 }) 38 39 Context("when writing", func() { 40 It("writes", func() { 41 frame := &StopSendingFrame{ 42 StreamID: 0xdeadbeefcafe, 43 ErrorCode: 0xdecafbad, 44 } 45 b, err := frame.Append(nil, protocol.Version1) 46 Expect(err).ToNot(HaveOccurred()) 47 expected := []byte{stopSendingFrameType} 48 expected = append(expected, encodeVarInt(0xdeadbeefcafe)...) 49 expected = append(expected, encodeVarInt(0xdecafbad)...) 50 Expect(b).To(Equal(expected)) 51 }) 52 53 It("has the correct min length", func() { 54 frame := &StopSendingFrame{ 55 StreamID: 0xdeadbeef, 56 ErrorCode: 0x1234567, 57 } 58 Expect(frame.Length(protocol.Version1)).To(BeEquivalentTo(1 + quicvarint.Len(0xdeadbeef) + quicvarint.Len(0x1234567))) 59 }) 60 }) 61 })