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

96 lines
2.2 KiB
Go
Raw Normal View History

2021-04-10 03:40:42 +02:00
package commands
import (
"os/exec"
"testing"
"github.com/jesseduffield/lazygit/pkg/test"
"github.com/stretchr/testify/assert"
)
// TestGitCommandRebaseBranch is a function.
func TestGitCommandRebaseBranch(t *testing.T) {
type scenario struct {
testName string
arg string
command func(string, ...string) *exec.Cmd
test func(error)
}
scenarios := []scenario{
{
"successful rebase",
"master",
test.CreateMockCommand(t, []*test.CommandSwapper{
{
Expect: "git rebase --interactive --autostash --keep-empty master",
Replace: "echo",
},
}),
func(err error) {
assert.NoError(t, err)
},
},
{
"unsuccessful rebase",
"master",
test.CreateMockCommand(t, []*test.CommandSwapper{
{
Expect: "git rebase --interactive --autostash --keep-empty master",
Replace: "test",
},
}),
func(err error) {
assert.Error(t, err)
},
},
}
gitCmd := NewDummyGitCommand()
for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) {
gitCmd.OSCommand.Command = s.command
s.test(gitCmd.RebaseBranch(s.arg))
})
}
}
2021-12-30 04:11:58 +02:00
// // TestGitCommandSkipEditorCommand confirms that SkipEditorCommand injects
// // environment variables that suppress an interactive editor
// func TestGitCommandSkipEditorCommand(t *testing.T) {
// cmd := NewDummyGitCommand()
2021-04-10 03:40:42 +02:00
2021-12-30 04:11:58 +02:00
// cmd.OSCommand.SetBeforeExecuteCmd(func(cmdObj oscommands.ICmdObj) {
// test.AssertContainsMatch(
// t,
// cmdObj.GetEnvVars(),
// regexp.MustCompile("^VISUAL="),
// "expected VISUAL to be set for a non-interactive external command",
// )
2021-04-10 03:40:42 +02:00
2021-12-30 04:11:58 +02:00
// test.AssertContainsMatch(
// t,
// cmdObj.GetEnvVars(),
// regexp.MustCompile("^EDITOR="),
// "expected EDITOR to be set for a non-interactive external command",
// )
2021-04-10 03:40:42 +02:00
2021-12-30 04:11:58 +02:00
// test.AssertContainsMatch(
// t,
// cmdObj.GetEnvVars(),
// regexp.MustCompile("^GIT_EDITOR="),
// "expected GIT_EDITOR to be set for a non-interactive external command",
// )
2021-04-10 03:40:42 +02:00
2021-12-30 04:11:58 +02:00
// test.AssertContainsMatch(
// t,
// cmdObj.GetEnvVars(),
// regexp.MustCompile("^LAZYGIT_CLIENT_COMMAND=EXIT_IMMEDIATELY$"),
// "expected LAZYGIT_CLIENT_COMMAND to be set for a non-interactive external command",
// )
// })
2021-04-10 03:40:42 +02:00
2021-12-30 04:11:58 +02:00
// _ = cmd.runSkipEditorCommand("true")
// }