github.com/clubpay/ronykit/kit@v0.14.4-0.20240515065620-d0dace45cbc7/errors/error_test.go (about) 1 package errors_test 2 3 import ( 4 builtinErr "errors" 5 "fmt" 6 "testing" 7 8 "github.com/clubpay/ronykit/kit/errors" 9 . "github.com/onsi/ginkgo/v2" 10 . "github.com/onsi/gomega" 11 ) 12 13 var ( 14 errInternal = builtinErr.New("internal error") 15 errRuntime = builtinErr.New("runtime error") 16 errEndOfFile = builtinErr.New("end of file") 17 18 errWrappedInternal = fmt.Errorf("wrapped error: %w", errInternal) 19 ) 20 21 func TestError(t *testing.T) { 22 RegisterFailHandler(Fail) 23 RunSpecs(t, "Ronykit Suite") 24 } 25 26 var _ = Describe("WrapError", func() { 27 we := errors.Wrap(errRuntime, errEndOfFile) 28 29 It("Wrap 1", func() { 30 Expect(builtinErr.Is(we, errRuntime)).To(BeTrue()) 31 Expect(builtinErr.Is(we, errEndOfFile)).To(BeTrue()) 32 Expect(we.Error()).To(BeEquivalentTo("runtime error: end of file")) 33 }) 34 35 It("Wrap 2", func() { 36 wwe := errors.Wrap(errInternal, we) 37 Expect(builtinErr.Is(wwe, errInternal)).To(BeTrue()) 38 Expect(builtinErr.Is(wwe, errRuntime)).To(BeTrue()) 39 Expect(builtinErr.Is(wwe, errEndOfFile)).To(BeTrue()) 40 Expect(wwe.Error()).To(BeEquivalentTo("internal error: runtime error: end of file")) 41 }) 42 43 It("Wrap 3", func() { 44 wwi := errors.Wrap(errWrappedInternal, we) 45 Expect(builtinErr.Is(wwi, errWrappedInternal)).To(BeTrue()) 46 Expect(builtinErr.Is(wwi, errInternal)).To(BeTrue()) 47 Expect(builtinErr.Is(wwi, errRuntime)).To(BeTrue()) 48 Expect(builtinErr.Is(wwi, errEndOfFile)).To(BeTrue()) 49 Expect(wwi.Error()).To(BeEquivalentTo("wrapped error: internal error: runtime error: end of file")) 50 }) 51 })