Skip to content

Commit

Permalink
Add RunCmdAndVerifyFailureContainsText test util func
Browse files Browse the repository at this point in the history
  • Loading branch information
eladlachmi committed May 23, 2024
1 parent 21a55e3 commit f1c08de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion esti/lakectl_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 12 additions & 2 deletions esti/lakectl_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit f1c08de

Please sign in to comment.