From 1ecd74c357101dbedbd2f8afcb81954b281f6e57 Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Thu, 6 Sep 2018 23:01:31 +0200 Subject: [PATCH] commands/git : add tests for GetCommitsToPush --- pkg/commands/git_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index d8007489a..cd0c86198 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -595,6 +595,44 @@ func TestGitCommandUpstreamDifferentCount(t *testing.T) { } } +func TestGitCommandGetCommitsToPush(t *testing.T) { + type scenario struct { + testName string + command func(string, ...string) *exec.Cmd + test func([]string) + } + + scenarios := []scenario{ + { + "Can't retrieve pushable commits", + func(string, ...string) *exec.Cmd { + return exec.Command("exit 1") + }, + func(pushables []string) { + assert.EqualValues(t, []string{}, pushables) + }, + }, + { + "Retrieve pushable commits", + func(cmd string, args ...string) *exec.Cmd { + return exec.Command("echo", "8a2bb0e\n78976bc") + }, + func(pushables []string) { + assert.Len(t, pushables, 2) + assert.EqualValues(t, []string{"8a2bb0e", "78976bc"}, pushables) + }, + }, + } + + for _, s := range scenarios { + t.Run(s.testName, func(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = s.command + s.test(gitCmd.GetCommitsToPush()) + }) + } +} + func TestGitCommandDiff(t *testing.T) { gitCommand := newDummyGitCommand() assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh"))