mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Added new helper methods FailfWithOffset and ExpectNoErrorWithOffset.
This commit is contained in:
parent
c13d8917c2
commit
30b3472f89
@ -286,9 +286,15 @@ func Logf(format string, args ...interface{}) {
|
||||
}
|
||||
|
||||
func Failf(format string, args ...interface{}) {
|
||||
FailfWithOffset(1, format, args...)
|
||||
}
|
||||
|
||||
// FailfWithOffset calls "Fail" and logs the error at "offset" levels above its caller
|
||||
// (for example, for call chain f -> g -> FailfWithOffset(1, ...) error would be logged for "f").
|
||||
func FailfWithOffset(offset int, format string, args ...interface{}) {
|
||||
msg := fmt.Sprintf(format, args...)
|
||||
log("INFO", msg)
|
||||
Fail(nowStamp()+": "+msg, 1)
|
||||
Fail(nowStamp()+": "+msg, 1 + offset)
|
||||
}
|
||||
|
||||
func Skipf(format string, args ...interface{}) {
|
||||
@ -1917,10 +1923,16 @@ func randomSuffix() string {
|
||||
}
|
||||
|
||||
func ExpectNoError(err error, explain ...interface{}) {
|
||||
ExpectNoErrorWithOffset(1, err, explain...)
|
||||
}
|
||||
|
||||
// ExpectNoErrorWithOffset checks if "err" is set, and if so, fails assertion while logging the error at "offset" levels above its caller
|
||||
// (for example, for call chain f -> g -> ExpectNoErrorWithOffset(1, ...) error would be logged for "f").
|
||||
func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{}) {
|
||||
if err != nil {
|
||||
Logf("Unexpected error occurred: %v", err)
|
||||
}
|
||||
ExpectWithOffset(1, err).NotTo(HaveOccurred(), explain...)
|
||||
ExpectWithOffset(1 + offset, err).NotTo(HaveOccurred(), explain...)
|
||||
}
|
||||
|
||||
func ExpectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interface{}) {
|
||||
|
Loading…
Reference in New Issue
Block a user