forked from RamenDR/ramen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When a test fails, we the go test framework logs the failure in an unhelpful way. This works for unit tests, since they are simple and do not log anything, but our tests are complex and log a lot. The failure logs from go test are hidden and hard to find. This change add wrappers for t.Fatal, t.FailNow, t.Skip, and t.Skipf so they use our logger instead of the go test framework logger. This ensures that every failure will have a proper ERROR log which is very easy to find. Errors logs include a traceback making it easier to understand the failure. When handling errors in parent tests we don't have any context and we cannot log any useful error. The actual error that failed the sub test already logged the error, so we just mark the test as failed with util.FailNow(). Part-of: RamenDR#1595 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
- Loading branch information
Showing
4 changed files
with
61 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-FileCopyrightText: The RamenDR authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package util | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
// Fatal logs an error and fails the test. | ||
func Fatal(t *testing.T, msg string, err error) { | ||
t.Helper() | ||
Ctx.Log.Error(err, msg) | ||
t.FailNow() | ||
} | ||
|
||
// FailNow fails the tests silently. Use for parent tests. | ||
func FailNow(t *testing.T) { | ||
t.Helper() | ||
t.FailNow() | ||
} | ||
|
||
// Skipf logs formatted message the skips the test. | ||
func Skipf(t *testing.T, format string, args ...any) { | ||
t.Helper() | ||
Skip(t, fmt.Sprintf(format, args...)) | ||
} | ||
|
||
// Skip log msg and skips the test. | ||
func Skip(t *testing.T, msg string) { | ||
t.Helper() | ||
Ctx.Log.Info(msg) | ||
t.SkipNow() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters