ktesting: fix ExpectNoError

The error wasn't actually being checked and generating the description was
broken.
This commit is contained in:
Patrick Ohly 2024-02-20 14:03:09 +01:00
parent b069ef6e13
commit fe10bfb044

View File

@ -63,10 +63,15 @@ func expect(tCtx TContext, actual interface{}, extra ...interface{}) gomega.Asse
} }
func expectNoError(tCtx TContext, err error, explain ...interface{}) { func expectNoError(tCtx TContext, err error, explain ...interface{}) {
if err == nil {
return
}
tCtx.Helper() tCtx.Helper()
description := buildDescription(explain) description := buildDescription(explain...)
if errors.Is(err, ErrFailure) {
var failure FailureError var failure FailureError
if errors.As(err, &failure) { if errors.As(err, &failure) {
if backtrace := failure.Backtrace(); backtrace != "" { if backtrace := failure.Backtrace(); backtrace != "" {
@ -75,6 +80,7 @@ func expectNoError(tCtx TContext, err error, explain ...interface{}) {
} }
tCtx.Logf("Failed at:\n %s", strings.ReplaceAll(backtrace, "\n", "\n ")) tCtx.Logf("Failed at:\n %s", strings.ReplaceAll(backtrace, "\n", "\n "))
} }
}
if description != "" { if description != "" {
tCtx.Fatalf("%s: %s", description, err.Error()) tCtx.Fatalf("%s: %s", description, err.Error())
} }
@ -84,7 +90,7 @@ func expectNoError(tCtx TContext, err error, explain ...interface{}) {
if description == "" { if description == "" {
description = "Unexpected error" description = "Unexpected error"
} }
tCtx.Logf("%s: %s\n%s", description, format.Object(err, 1)) tCtx.Logf("%s:\n%s", description, format.Object(err, 1))
tCtx.Fatalf("%s: %v", description, err.Error()) tCtx.Fatalf("%s: %v", description, err.Error())
} }