From 45fa2571287ac45045b9d6127dc0a38538b4fa4f Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Tue, 28 Aug 2018 20:24:19 +0200 Subject: [PATCH] add test for StashSave and refactor StashSave method --- pkg/commands/git.go | 2 +- pkg/commands/git_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 9b3c72fd9..5a4d910d3 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -112,7 +112,7 @@ func (c *GitCommand) StashDo(index int, method string) error { // StashSave save stash // TODO: before calling this, check if there is anything to save func (c *GitCommand) StashSave(message string) error { - return c.OSCommand.RunCommand("git stash save " + c.OSCommand.Quote(message)) + return c.OSCommand.RunCommand(fmt.Sprintf("git stash save %s", c.OSCommand.Quote(message))) } // MergeStatusFiles merge status files diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index 554ffbd1a..920f527a8 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -173,6 +173,18 @@ func TestGitCommandStashDo(t *testing.T) { assert.NoError(t, gitCmd.StashDo(1, "drop")) } +func TestGitCommandStashSave(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"stash", "save", "A stash message"}, args) + + return exec.Command("echo") + } + + assert.NoError(t, gitCmd.StashSave("A stash message")) +} + func TestGitCommandDiff(t *testing.T) { gitCommand := newDummyGitCommand() assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh"))