From 05c0f4a298a82a167b85323ac189bf6a528f288a Mon Sep 17 00:00:00 2001 From: Dave Chen Date: Tue, 29 Mar 2022 14:34:54 +0800 Subject: [PATCH] Define the const of `GINKGO_PANIC` directly `ginkgo.GINKGO_PANIC` is not available and cannot be imported directly. Signed-off-by: Dave Chen --- test/e2e/framework/ginkgowrapper/wrapper.go | 12 +++++++++++- test/e2e/framework/skipper/skipper.go | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/test/e2e/framework/ginkgowrapper/wrapper.go b/test/e2e/framework/ginkgowrapper/wrapper.go index 97ccbd896c0..6bbdb5d6177 100644 --- a/test/e2e/framework/ginkgowrapper/wrapper.go +++ b/test/e2e/framework/ginkgowrapper/wrapper.go @@ -37,8 +37,18 @@ type FailurePanic struct { FullStackTrace string // A full stack trace starting at the source of the failure } +const ginkgoFailurePanic = ` +Your test failed. +Ginkgo panics to prevent subsequent assertions from running. +Normally Ginkgo rescues this panic so you shouldn't see it. +But, if you make an assertion in a goroutine, Ginkgo can't capture the panic. +To circumvent this, you should call + defer GinkgoRecover() +at the top of the goroutine that caused this panic. +` + // String makes FailurePanic look like the old Ginkgo panic when printed. -func (FailurePanic) String() string { return ginkgo.GINKGO_PANIC } +func (FailurePanic) String() string { return ginkgoFailurePanic } // Fail wraps ginkgo.Fail so that it panics with more useful // information about the failure. This function will panic with a diff --git a/test/e2e/framework/skipper/skipper.go b/test/e2e/framework/skipper/skipper.go index 87f621b1127..99d506e0a8f 100644 --- a/test/e2e/framework/skipper/skipper.go +++ b/test/e2e/framework/skipper/skipper.go @@ -56,8 +56,18 @@ type SkipPanic struct { FullStackTrace string // A full stack trace starting at the source of the failure } +const ginkgoSkipPanic = ` +Your test was skipped. +Ginkgo panics to prevent subsequent assertions from running. +Normally Ginkgo rescues this panic so you shouldn't see it. +But, if you make an assertion in a goroutine, Ginkgo can't capture the panic. +To circumvent this, you should call + defer GinkgoRecover() +at the top of the goroutine that caused this panic. +` + // String makes SkipPanic look like the old Ginkgo panic when printed. -func (SkipPanic) String() string { return ginkgo.GINKGO_PANIC } +func (SkipPanic) String() string { return ginkgoSkipPanic } // Skip wraps ginkgo.Skip so that it panics with more useful // information about why the test is being skipped. This function will