From 30b3472f893d8b3d8aceebcd41f124b81bd2c7a6 Mon Sep 17 00:00:00 2001 From: Andrzej Wasylkowski Date: Fri, 2 Jun 2017 12:01:08 +0200 Subject: [PATCH] Added new helper methods FailfWithOffset and ExpectNoErrorWithOffset. --- test/e2e/framework/util.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 0f31c013ed9..8dd5aca4962 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -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{}) {