From ccc84fb00dbba2f8dd1eb8c5ad4ad1c8f746480a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20L=C3=B3pez?= <1953782+julio-lopez@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:21:59 -0700 Subject: [PATCH] test(cli): prefer require in cli_test_env (#4200) Facilitates troubleshooting test failures. --- tests/testenv/cli_test_env.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tests/testenv/cli_test_env.go b/tests/testenv/cli_test_env.go index 6a914d3c3..9972de658 100644 --- a/tests/testenv/cli_test_env.go +++ b/tests/testenv/cli_test_env.go @@ -117,9 +117,7 @@ func (e *CLITest) RunAndExpectSuccess(t *testing.T, args ...string) []string { t.Helper() stdout, _, err := e.Run(t, false, args...) - if err != nil { - t.Fatalf("'kopia %v' failed with %v", strings.Join(args, " "), err) - } + require.NoError(t, err, "'kopia %v' failed", strings.Join(args, " ")) return stdout } @@ -234,9 +232,7 @@ func (e *CLITest) RunAndExpectSuccessWithErrOut(t *testing.T, args ...string) (s t.Helper() stdout, stderr, err := e.Run(t, false, args...) - if err != nil { - t.Fatalf("'kopia %v' failed with %v", strings.Join(args, " "), err) - } + require.NoError(t, err, "'kopia %v' failed", strings.Join(args, " ")) return stdout, stderr } @@ -248,9 +244,7 @@ func (e *CLITest) RunAndExpectFailure(t *testing.T, args ...string) (stdout, std var err error stdout, stderr, err = e.Run(t, true, args...) - if err == nil { - t.Fatalf("'kopia %v' succeeded, but expected failure", strings.Join(args, " ")) - } + require.Error(t, err, "'kopia %v' succeeded, but expected failure", strings.Join(args, " ")) return stdout, stderr } @@ -260,9 +254,7 @@ func (e *CLITest) RunAndVerifyOutputLineCount(t *testing.T, wantLines int, args t.Helper() lines := e.RunAndExpectSuccess(t, args...) - if len(lines) != wantLines { - t.Fatalf("unexpected list of results of 'kopia %v': %v lines (%v) wanted %v", strings.Join(args, " "), len(lines), lines, wantLines) - } + require.Len(t, lines, wantLines, "unexpected output lines for 'kopia %v', lines:\n %s", strings.Join(args, " "), strings.Join(lines, "\n ")) return lines }