diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-09-25 20:25:04 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2018-09-25 20:25:04 +1000 |
commit | fb9596a3fffa5c707b27fb0eee1768d76aefd206 (patch) | |
tree | 62824f08d2466e2b00c6851a388ec79f0b26bae1 /pkg | |
parent | 0d33a746ba679a2ca23066aa9bea3305506aae14 (diff) |
add test for getMergeBase
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/git_test.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index 5a331ea18..d5b87a1f1 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -1684,3 +1684,82 @@ func TestGitCommandDiff(t *testing.T) { }) } } + +func TestGitCommandGetMergeBase(t *testing.T) { + type scenario struct { + testName string + command func(string, ...string) *exec.Cmd + test func(string, error) + } + + scenarios := []scenario{ + { + "swallows an error if the call to merge-base returns an error", + func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + + switch args[0] { + case "symbolic-ref": + assert.EqualValues(t, []string{"symbolic-ref", "--short", "HEAD"}, args) + return exec.Command("echo", "master") + case "merge-base": + assert.EqualValues(t, []string{"merge-base", "HEAD", "master"}, args) + return exec.Command("test") + } + return nil + }, + func(output string, err error) { + assert.NoError(t, err) + assert.EqualValues(t, "", output) + }, + }, + { + "returns the commit when master", + func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + + switch args[0] { + case "symbolic-ref": + assert.EqualValues(t, []string{"symbolic-ref", "--short", "HEAD"}, args) + return exec.Command("echo", "master") + case "merge-base": + assert.EqualValues(t, []string{"merge-base", "HEAD", "master"}, args) + return exec.Command("echo", "blah") + } + return nil + }, + func(output string, err error) { + assert.NoError(t, err) + assert.Equal(t, "blah\n", output) + }, + }, + { + "checks against develop when a feature branch", + func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + + switch args[0] { + case "symbolic-ref": + assert.EqualValues(t, []string{"symbolic-ref", "--short", "HEAD"}, args) + return exec.Command("echo", "feature/test") + case "merge-base": + assert.EqualValues(t, []string{"merge-base", "HEAD", "develop"}, args) + return exec.Command("echo", "blah") + } + return nil + }, + func(output string, err error) { + assert.NoError(t, err) + assert.Equal(t, "blah\n", output) + }, + }, + } + + for _, s := range scenarios { + t.Run(s.testName, func(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = s.command + s.test(gitCmd.getMergeBase()) + }) + } +} |