github.com/onsi/gomega@v1.32.0/internal/polling_signal_error_test.go (about) 1 package internal_test 2 3 import ( 4 "errors" 5 "fmt" 6 7 . "github.com/onsi/ginkgo/v2" 8 . "github.com/onsi/gomega" 9 "github.com/onsi/gomega/internal" 10 ) 11 12 var _ = Describe("PollingSignalError", func() { 13 Describe("StopTrying", func() { 14 Describe("building StopTrying errors", func() { 15 It("returns a correctly configured StopTrying error", func() { 16 st := StopTrying("I've tried 17 times - give up!") 17 Ω(st.Error()).Should(Equal("I've tried 17 times - give up!")) 18 Ω(errors.Unwrap(st)).Should(BeNil()) 19 Ω(st.(*internal.PollingSignalErrorImpl).IsStopTrying()).Should(BeTrue()) 20 }) 21 }) 22 23 Describe("Wrapping other errors", func() { 24 It("can wrap other errors", func() { 25 st := StopTrying("Welp! Time to give up") 26 Ω(st.Error()).Should(Equal("Welp! Time to give up")) 27 st = st.Wrap(fmt.Errorf("ERR_GIVE_UP")) 28 Ω(errors.Unwrap(st)).Should(Equal(fmt.Errorf("ERR_GIVE_UP"))) 29 Ω(st.Error()).Should(Equal("Welp! Time to give up: ERR_GIVE_UP")) 30 }) 31 }) 32 33 Describe("When attaching objects", func() { 34 It("attaches them, with their descriptions", func() { 35 st := StopTrying("Welp!").Attach("Max retries attained", 17).Attach("Got this response", "FLOOP").(*internal.PollingSignalErrorImpl) 36 Ω(st.Attachments).Should(HaveLen(2)) 37 Ω(st.Attachments[0]).Should(Equal(internal.PollingSignalErrorAttachment{"Max retries attained", 17})) 38 Ω(st.Attachments[1]).Should(Equal(internal.PollingSignalErrorAttachment{"Got this response", "FLOOP"})) 39 }) 40 }) 41 42 Describe("when invoking Now()", func() { 43 It("should panic with itself", func() { 44 st := StopTrying("bam").(*internal.PollingSignalErrorImpl) 45 Ω(st.Now).Should(PanicWith(st)) 46 }) 47 }) 48 49 Describe("AsPollingSignalError", func() { 50 It("should return false for nils", func() { 51 st, ok := internal.AsPollingSignalError(nil) 52 Ω(st).Should(BeNil()) 53 Ω(ok).Should(BeFalse()) 54 }) 55 56 It("should work when passed a StopTrying error", func() { 57 st, ok := internal.AsPollingSignalError(StopTrying("bam")) 58 Ω(st).Should(Equal(StopTrying("bam"))) 59 Ω(ok).Should(BeTrue()) 60 }) 61 62 It("should work when passed a wrapped error", func() { 63 st, ok := internal.AsPollingSignalError(fmt.Errorf("STOP TRYING %w", StopTrying("bam"))) 64 Ω(st).Should(Equal(StopTrying("bam"))) 65 Ω(ok).Should(BeTrue()) 66 }) 67 }) 68 }) 69 })