summaryrefslogtreecommitdiffstats
path: root/pkg/commands/sync_test.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-04-10 11:40:42 +1000
committerJesse Duffield <jessedduffield@gmail.com>2021-04-10 11:54:38 +1000
commite42e7e5cbd9d075ee24ae8f91ba9e12bdd42fafc (patch)
tree61d65a544c056b3bf0384cf6954b81b292eb4b07 /pkg/commands/sync_test.go
parent93fac1f3124f87009091230f61cc13b5e5473cb5 (diff)
fix commit amend
Diffstat (limited to 'pkg/commands/sync_test.go')
-rw-r--r--pkg/commands/sync_test.go98
1 files changed, 98 insertions, 0 deletions
diff --git a/pkg/commands/sync_test.go b/pkg/commands/sync_test.go
new file mode 100644
index 000000000..b6a52fe63
--- /dev/null
+++ b/pkg/commands/sync_test.go
@@ -0,0 +1,98 @@
+package commands
+
+import (
+ "os/exec"
+ "testing"
+
+ "github.com/jesseduffield/lazygit/pkg/secureexec"
+ "github.com/stretchr/testify/assert"
+)
+
+// TestGitCommandPush is a function.
+func TestGitCommandPush(t *testing.T) {
+ type scenario struct {
+ testName string
+ getGitConfigValue func(string) (string, error)
+ command func(string, ...string) *exec.Cmd
+ forcePush bool
+ test func(error)
+ }
+
+ scenarios := []scenario{
+ {
+ "Push with force disabled, follow-tags on",
+ func(string) (string, error) {
+ return "", nil
+ },
+ func(cmd string, args ...string) *exec.Cmd {
+ assert.EqualValues(t, "git", cmd)
+ assert.EqualValues(t, []string{"push", "--follow-tags"}, args)
+
+ return secureexec.Command("echo")
+ },
+ false,
+ func(err error) {
+ assert.NoError(t, err)
+ },
+ },
+ {
+ "Push with force enabled, follow-tags on",
+ func(string) (string, error) {
+ return "", nil
+ },
+ func(cmd string, args ...string) *exec.Cmd {
+ assert.EqualValues(t, "git", cmd)
+ assert.EqualValues(t, []string{"push", "--follow-tags", "--force-with-lease"}, args)
+
+ return secureexec.Command("echo")
+ },
+ true,
+ func(err error) {
+ assert.NoError(t, err)
+ },
+ },
+ {
+ "Push with force disabled, follow-tags off",
+ func(string) (string, error) {
+ return "false", nil
+ },
+ func(cmd string, args ...string) *exec.Cmd {
+ assert.EqualValues(t, "git", cmd)
+ assert.EqualValues(t, []string{"push"}, args)
+
+ return secureexec.Command("echo")
+ },
+ false,
+ func(err error) {
+ assert.NoError(t, err)
+ },
+ },
+ {
+ "Push with an error occurring, follow-tags on",
+ func(string) (string, error) {
+ return "", nil
+ },
+ func(cmd string, args ...string) *exec.Cmd {
+ assert.EqualValues(t, "git", cmd)
+ assert.EqualValues(t, []string{"push", "--follow-tags"}, args)
+ return secureexec.Command("test")
+ },
+ false,
+ func(err error) {
+ assert.Error(t, err)
+ },
+ },
+ }
+
+ for _, s := range scenarios {
+ t.Run(s.testName, func(t *testing.T) {
+ gitCmd := NewDummyGitCommand()
+ gitCmd.OSCommand.Command = s.command
+ gitCmd.getGitConfigValue = s.getGitConfigValue
+ err := gitCmd.Push("test", s.forcePush, "", "", func(passOrUname string) string {
+ return "\n"
+ })
+ s.test(err)
+ })
+ }
+}