From f1c08de1d57044cc40b30f141cbd8301ffd6d2a3 Mon Sep 17 00:00:00 2001 From: Elad Lachmi Date: Thu, 23 May 2024 18:41:20 +0300 Subject: [PATCH] Add RunCmdAndVerifyFailureContainsText test util func --- esti/lakectl_local_test.go | 2 +- esti/lakectl_util.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/esti/lakectl_local_test.go b/esti/lakectl_local_test.go index 645e8ed849b..0f4eddcaae9 100644 --- a/esti/lakectl_local_test.go +++ b/esti/lakectl_local_test.go @@ -572,7 +572,7 @@ func TestLakectlLocal_commit_remote_uncommitted(t *testing.T) { } cmd := fmt.Sprintf("%s local commit -m test %s", Lakectl(), dataDir) if tc.expectFailure { - RunCmdAndVerifyFailure(t, cmd, false, tc.expectedMessage, vars) + RunCmdAndVerifyFailureContainsText(t, cmd, false, tc.expectedMessage, vars) } else { RunCmdAndVerifyContainsText(t, cmd, false, tc.expectedMessage, vars) } diff --git a/esti/lakectl_util.go b/esti/lakectl_util.go index 6fbc937630b..c199c392b6c 100644 --- a/esti/lakectl_util.go +++ b/esti/lakectl_util.go @@ -145,11 +145,21 @@ func RunCmdAndVerifySuccessWithFile(t *testing.T, cmd string, isTerminal bool, g } func RunCmdAndVerifyContainsText(t *testing.T, cmd string, isTerminal bool, expectedRaw string, vars map[string]string) { + t.Helper() + runCmdAndVerifyContainsText(t, cmd, false, isTerminal, expectedRaw, vars) +} + +func RunCmdAndVerifyFailureContainsText(t *testing.T, cmd string, isTerminal bool, expectedRaw string, vars map[string]string) { + t.Helper() + runCmdAndVerifyContainsText(t, cmd, true, isTerminal, expectedRaw, vars) +} + +func runCmdAndVerifyContainsText(t *testing.T, cmd string, expectFail, isTerminal bool, expectedRaw string, vars map[string]string) { t.Helper() s := sanitize(expectedRaw, vars) expected, err := expandVariables(s, vars) - require.NoErrorf(t, err, "Variable embed failed - %s", err) - sanitizedResult := runCmd(t, cmd, false, isTerminal, vars) + require.NoError(t, err, "Variable embed failed - %s", err) + sanitizedResult := runCmd(t, cmd, expectFail, isTerminal, vars) require.Contains(t, sanitizedResult, expected) }