github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/http3/error_test.go (about) 1 package http3 2 3 import ( 4 "errors" 5 6 "github.com/metacubex/quic-go" 7 8 . "github.com/onsi/ginkgo/v2" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("HTTP/3 errors", func() { 13 It("converts", func() { 14 Expect(maybeReplaceError(nil)).To(BeNil()) 15 Expect(maybeReplaceError(errors.New("foobar"))).To(MatchError("foobar")) 16 Expect(maybeReplaceError(&quic.StreamError{ 17 ErrorCode: 1337, 18 Remote: true, 19 })).To(Equal(&Error{ 20 Remote: true, 21 ErrorCode: 1337, 22 })) 23 Expect(maybeReplaceError(&quic.ApplicationError{ 24 ErrorCode: 42, 25 Remote: true, 26 ErrorMessage: "foobar", 27 })).To(Equal(&Error{ 28 Remote: true, 29 ErrorCode: 42, 30 ErrorMessage: "foobar", 31 })) 32 }) 33 34 It("has a string representation", func() { 35 Expect((&Error{ErrorCode: 0x10c, Remote: true}).Error()).To(Equal("H3_REQUEST_CANCELLED")) 36 Expect((&Error{ErrorCode: 0x10c, Remote: true, ErrorMessage: "foobar"}).Error()).To(Equal("H3_REQUEST_CANCELLED: foobar")) 37 Expect((&Error{ErrorCode: 0x10c, Remote: false}).Error()).To(Equal("H3_REQUEST_CANCELLED (local)")) 38 Expect((&Error{ErrorCode: 0x10c, Remote: false, ErrorMessage: "foobar"}).Error()).To(Equal("H3_REQUEST_CANCELLED (local): foobar")) 39 Expect((&Error{ErrorCode: 0x1337, Remote: true}).Error()).To(Equal("H3 error (0x1337)")) 40 }) 41 })