e2e framework: include additional stack backtrace in failures
When a Gomega failure is converted to an error, the stack at the time when the failure occurs may be useful: error wrapping provides some bread crumbs that can be followed to determine where the failure really occurred, but error wrapping may be missing or ambiguous. To provide the additional information, a FailureError now includes a full stack backtrace. The backtrace intentionally makes no attempt to exclude framework functions besides the gomega support itself because helpers like e2e/framework/pod may be relevant. That backtrace is not included in the failure message for the sake of brevity. Instead, it gets logged as part of the test's output.
This commit is contained in:
@@ -25,6 +25,20 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// This test is sensitive to line numbering.
|
||||
// The following lines can be removed to compensate for import changes.
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// This must be line #40.
|
||||
|
||||
func TestNewGomega(t *testing.T) {
|
||||
if err := Gomega().Expect("hello").To(gomega.Equal("hello")); err != nil {
|
||||
t.Errorf("unexpected failure: %s", err.Error())
|
||||
@@ -38,4 +52,11 @@ not to equal
|
||||
if !errors.Is(err, ErrFailure) {
|
||||
t.Errorf("expected error that is ErrFailure, got %T: %+v", err, err)
|
||||
}
|
||||
var failure FailureError
|
||||
if !errors.As(err, &failure) {
|
||||
t.Errorf("expected error that can be copied to FailureError, got %T: %+v", err, err)
|
||||
} else {
|
||||
assert.Regexp(t, `^k8s.io/kubernetes/test/e2e/framework.TestNewGomega\(0x[0-9A-Fa-f]*\)
|
||||
.*/test/e2e/framework/expect_test.go:46`, failure.Backtrace())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user