summaryrefslogtreecommitdiffstats
path: root/pkg/commands/sync_test.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-10-23 09:52:19 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-10-23 10:26:47 +1100
commitb6a5e9d615f0fee7d76f5db33ff48bf32f0ef98b (patch)
tree32644c7c8810c2217cb26d750e5eafee7e07760f /pkg/commands/sync_test.go
parent5011cac7ea2b1d8ce9d9976b59c17f579c270fd9 (diff)
use cached git config
Diffstat (limited to 'pkg/commands/sync_test.go')
-rw-r--r--pkg/commands/sync_test.go112
1 files changed, 13 insertions, 99 deletions
diff --git a/pkg/commands/sync_test.go b/pkg/commands/sync_test.go
index f793639be..924bd56ef 100644
--- a/pkg/commands/sync_test.go
+++ b/pkg/commands/sync_test.go
@@ -11,11 +11,10 @@ import (
// 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
- opts PushOpts
- test func(error)
+ testName string
+ command func(string, ...string) *exec.Cmd
+ opts PushOpts
+ test func(error)
}
prompt := func(passOrUname string) string {
@@ -24,13 +23,10 @@ func TestGitCommandPush(t *testing.T) {
scenarios := []scenario{
{
- "Push with force disabled, follow-tags on",
- func(string) (string, error) {
- return "", nil
- },
+ "Push with force disabled",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "git", cmd)
- assert.EqualValues(t, []string{"push", "--follow-tags"}, args)
+ assert.EqualValues(t, []string{"push"}, args)
return secureexec.Command("echo")
},
@@ -40,13 +36,10 @@ func TestGitCommandPush(t *testing.T) {
},
},
{
- "Push with force enabled, follow-tags on",
- func(string) (string, error) {
- return "", nil
- },
+ "Push with force enabled",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "git", cmd)
- assert.EqualValues(t, []string{"push", "--follow-tags", "--force-with-lease"}, args)
+ assert.EqualValues(t, []string{"push", "--force-with-lease"}, args)
return secureexec.Command("echo")
},
@@ -56,29 +49,10 @@ func TestGitCommandPush(t *testing.T) {
},
},
{
- "Push with force disabled, follow-tags off",
- func(string) (string, error) {
- return "false", nil
- },
+ "Push with an error occurring",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "git", cmd)
assert.EqualValues(t, []string{"push"}, args)
-
- return secureexec.Command("echo")
- },
- PushOpts{Force: false, PromptUserForCredential: prompt},
- 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")
},
PushOpts{Force: false, PromptUserForCredential: prompt},
@@ -87,10 +61,7 @@ func TestGitCommandPush(t *testing.T) {
},
},
{
- "Push with force disabled, follow-tags off, upstream supplied",
- func(string) (string, error) {
- return "false", nil
- },
+ "Push with force disabled, upstream supplied",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "git", cmd)
assert.EqualValues(t, []string{"push", "origin", "master"}, args)
@@ -108,10 +79,7 @@ func TestGitCommandPush(t *testing.T) {
},
},
{
- "Push with force disabled, follow-tags off, setting upstream",
- func(string) (string, error) {
- return "false", nil
- },
+ "Push with force disabled, setting upstream",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "git", cmd)
assert.EqualValues(t, []string{"push", "--set-upstream", "origin", "master"}, args)
@@ -130,10 +98,7 @@ func TestGitCommandPush(t *testing.T) {
},
},
{
- "Push with force enabled, follow-tags off, setting upstream",
- func(string) (string, error) {
- return "false", nil
- },
+ "Push with force enabled, setting upstream",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "git", cmd)
assert.EqualValues(t, []string{"push", "--force-with-lease", "--set-upstream", "origin", "master"}, args)
@@ -153,9 +118,6 @@ func TestGitCommandPush(t *testing.T) {
},
{
"Push with remote branch but no origin",
- func(string) (string, error) {
- return "false", nil
- },
func(cmd string, args ...string) *exec.Cmd {
return nil
},
@@ -172,10 +134,7 @@ func TestGitCommandPush(t *testing.T) {
},
},
{
- "Push with force disabled, follow-tags off, upstream supplied",
- func(string) (string, error) {
- return "false", nil
- },
+ "Push with force disabled, upstream supplied",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "git", cmd)
assert.EqualValues(t, []string{"push", "origin", "master"}, args)
@@ -192,57 +151,12 @@ func TestGitCommandPush(t *testing.T) {
assert.NoError(t, err)
},
},
- {
- "Push with force disabled, follow-tags off, setting upstream",
- func(string) (string, error) {
- return "false", nil
- },
- func(cmd string, args ...string) *exec.Cmd {
- assert.EqualValues(t, "git", cmd)
- assert.EqualValues(t, []string{"push", "--set-upstream", "origin", "master"}, args)
-
- return secureexec.Command("echo")
- },
- PushOpts{
- Force: false,
- UpstreamRemote: "origin",
- UpstreamBranch: "master",
- PromptUserForCredential: prompt,
- SetUpstream: true,
- },
- func(err error) {
- assert.NoError(t, err)
- },
- },
- {
- "Push with force enabled, follow-tags off, setting upstream",
- func(string) (string, error) {
- return "false", nil
- },
- func(cmd string, args ...string) *exec.Cmd {
- assert.EqualValues(t, "git", cmd)
- assert.EqualValues(t, []string{"push", "--force-with-lease", "--set-upstream", "origin", "master"}, args)
-
- return secureexec.Command("echo")
- },
- PushOpts{
- Force: true,
- UpstreamRemote: "origin",
- UpstreamBranch: "master",
- PromptUserForCredential: prompt,
- SetUpstream: true,
- },
- func(err error) {
- assert.NoError(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(s.opts)
s.test(err)
})