summaryrefslogtreecommitdiffstats
path: root/pkg/commands/git_test.go
diff options
context:
space:
mode:
authorAnthony HAMON <hamon.anth@gmail.com>2018-09-12 20:43:03 +0200
committerAnthony HAMON <hamon.anth@gmail.com>2018-09-12 20:43:03 +0200
commit65a24d70c332b0ff8f7e10999ab73260a3336fe7 (patch)
tree1d67573e3dfada36832db9704f0b323177686909 /pkg/commands/git_test.go
parent79940b7ba9047965cbe35f159eac3d133e229da7 (diff)
commands/git : add tests on SquashPreviousTwoCommits
Diffstat (limited to 'pkg/commands/git_test.go')
-rw-r--r--pkg/commands/git_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go
index bda3ea225..0bcbdb7dd 100644
--- a/pkg/commands/git_test.go
+++ b/pkg/commands/git_test.go
@@ -953,6 +953,69 @@ func TestGitCommandPush(t *testing.T) {
}
}
+func TestGitCommandSquashPreviousTwoCommits(t *testing.T) {
+ type scenario struct {
+ testName string
+ command func(string, ...string) *exec.Cmd
+ test func(error)
+ }
+
+ scenarios := []scenario{
+ {
+ "Git reset triggers an error",
+ func(cmd string, args ...string) *exec.Cmd {
+ assert.EqualValues(t, "git", cmd)
+ assert.EqualValues(t, []string{"reset", "--soft", "HEAD^"}, args)
+
+ return exec.Command("exit", "1")
+ },
+ func(err error) {
+ assert.NotNil(t, err)
+ },
+ },
+ {
+ "Git commit triggers an error",
+ func(cmd string, args ...string) *exec.Cmd {
+ if len(args) > 0 && args[0] == "reset" {
+ return exec.Command("echo")
+ }
+
+ assert.EqualValues(t, "git", cmd)
+ assert.EqualValues(t, []string{"commit", "--amend", "-m", "test"}, args)
+
+ return exec.Command("exit", "1")
+ },
+ func(err error) {
+ assert.NotNil(t, err)
+ },
+ },
+ {
+ "Stash succeeded",
+ func(cmd string, args ...string) *exec.Cmd {
+ if len(args) > 0 && args[0] == "reset" {
+ return exec.Command("echo")
+ }
+
+ assert.EqualValues(t, "git", cmd)
+ assert.EqualValues(t, []string{"commit", "--amend", "-m", "test"}, args)
+
+ return exec.Command("echo")
+ },
+ func(err error) {
+ assert.Nil(t, err)
+ },
+ },
+ }
+
+ for _, s := range scenarios {
+ t.Run(s.testName, func(t *testing.T) {
+ gitCmd := newDummyGitCommand()
+ gitCmd.OSCommand.command = s.command
+ s.test(gitCmd.SquashPreviousTwoCommits("test"))
+ })
+ }
+}
+
func TestGitCommandDiff(t *testing.T) {
gitCommand := newDummyGitCommand()
assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh"))