From 3472e9f26c43f943e106efc1a4b20dc3815a8b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Carpintero?= Date: Tue, 30 Apr 2024 17:01:39 +0200 Subject: [PATCH] Add tests --- cmd/foreach/foreach_test.go | 17 +++++++++++++++++ internal/executor/executor.go | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/foreach/foreach_test.go b/cmd/foreach/foreach_test.go index a674faa..de3de2b 100644 --- a/cmd/foreach/foreach_test.go +++ b/cmd/foreach/foreach_test.go @@ -151,6 +151,23 @@ func TestItRunsCommandInShellAgainstWorkingCopies(t *testing.T) { }) } +func TestItRunsCommandQuotedInShellAgainstWorkingCopied(t *testing.T) { + fakeExecutor := executor.NewAlwaysSucceedsFakeExecutor() + exec = fakeExecutor + + testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2") + + out, err := runCommand("some", "command", "with spaces") + assert.NoError(t, err) + assert.Contains(t, out, "turbolift foreach completed") + assert.Contains(t, out, "2 OK, 0 skipped") + + fakeExecutor.AssertCalledWith(t, [][]string{ + {"work/org/repo1", userShell(), "-c", "some command \"with spaces\""}, + {"work/org/repo2", userShell(), "-c", "some command \"with spaces\""}, + }) +} + func TestItSkipsMissingWorkingCopies(t *testing.T) { fakeExecutor := executor.NewAlwaysSucceedsFakeExecutor() exec = fakeExecutor diff --git a/internal/executor/executor.go b/internal/executor/executor.go index cb7912a..f9e13b0 100644 --- a/internal/executor/executor.go +++ b/internal/executor/executor.go @@ -86,7 +86,7 @@ func summarizedArgs(args []string) []string { result := []string{} for _, arg := range args { if len(arg) > 30 { - result = append(result, "...") + result = append(result, arg[:27]+"...") } else { result = append(result, arg) }