1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/commands/sync_test.go

94 lines
2.4 KiB
Go
Raw Normal View History

2021-04-10 03:40:42 +02:00
package commands
import (
"testing"
2021-12-31 01:04:32 +02:00
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
2021-04-10 03:40:42 +02:00
"github.com/stretchr/testify/assert"
)
func TestGitCommandPush(t *testing.T) {
type scenario struct {
2021-10-23 00:52:19 +02:00
testName string
opts PushOpts
2021-12-31 01:04:32 +02:00
test func(oscommands.ICmdObj, error)
}
2021-04-10 03:40:42 +02:00
scenarios := []scenario{
{
2021-12-31 01:04:32 +02:00
testName: "Push with force disabled",
opts: PushOpts{Force: false},
test: func(cmdObj oscommands.ICmdObj, err error) {
assert.Equal(t, cmdObj.ToString(), "git push")
2021-04-10 03:40:42 +02:00
assert.NoError(t, err)
},
},
{
2021-12-31 01:04:32 +02:00
testName: "Push with force enabled",
opts: PushOpts{Force: true},
test: func(cmdObj oscommands.ICmdObj, err error) {
assert.Equal(t, cmdObj.ToString(), "git push --force-with-lease")
2021-04-10 03:40:42 +02:00
assert.NoError(t, err)
},
},
{
2021-12-31 01:04:32 +02:00
testName: "Push with force disabled, upstream supplied",
opts: PushOpts{
Force: false,
UpstreamRemote: "origin",
UpstreamBranch: "master",
},
test: func(cmdObj oscommands.ICmdObj, err error) {
assert.Equal(t, cmdObj.ToString(), `git push "origin" "master"`)
assert.NoError(t, err)
},
},
{
2021-12-31 01:04:32 +02:00
testName: "Push with force disabled, setting upstream",
opts: PushOpts{
Force: false,
UpstreamRemote: "origin",
UpstreamBranch: "master",
SetUpstream: true,
},
test: func(cmdObj oscommands.ICmdObj, err error) {
assert.Equal(t, cmdObj.ToString(), `git push --set-upstream "origin" "master"`)
assert.NoError(t, err)
},
},
{
2021-12-31 01:04:32 +02:00
testName: "Push with force enabled, setting upstream",
opts: PushOpts{
Force: true,
UpstreamRemote: "origin",
UpstreamBranch: "master",
SetUpstream: true,
},
test: func(cmdObj oscommands.ICmdObj, err error) {
assert.Equal(t, cmdObj.ToString(), `git push --force-with-lease --set-upstream "origin" "master"`)
assert.NoError(t, err)
},
},
{
2021-12-31 01:04:32 +02:00
testName: "Push with remote branch but no origin",
opts: PushOpts{
Force: true,
UpstreamRemote: "",
UpstreamBranch: "master",
SetUpstream: true,
},
test: func(cmdObj oscommands.ICmdObj, err error) {
assert.Error(t, err)
assert.EqualValues(t, "Must specify a remote if specifying a branch", err.Error())
},
},
2021-04-10 03:40:42 +02:00
}
for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) {
2021-12-31 01:04:32 +02:00
gitCmd := NewDummyGitCommandWithRunner(oscommands.NewFakeRunner(t))
2022-01-02 01:34:33 +02:00
s.test(gitCmd.Sync.PushCmdObj(s.opts))
2021-04-10 03:40:42 +02:00
})
}
}