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