mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
ktesting: fix ExpectNoError
The error wasn't actually being checked and generating the description was broken.
This commit is contained in:
parent
b069ef6e13
commit
fe10bfb044
@ -63,17 +63,23 @@ 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...)
|
||||||
|
|
||||||
var failure FailureError
|
if errors.Is(err, ErrFailure) {
|
||||||
if errors.As(err, &failure) {
|
var failure FailureError
|
||||||
if backtrace := failure.Backtrace(); backtrace != "" {
|
if errors.As(err, &failure) {
|
||||||
if description != "" {
|
if backtrace := failure.Backtrace(); backtrace != "" {
|
||||||
tCtx.Log(description)
|
if description != "" {
|
||||||
|
tCtx.Log(description)
|
||||||
|
}
|
||||||
|
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())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user