1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/commands/git_commands/stash_test.go

81 lines
2.1 KiB
Go
Raw Normal View History

2022-01-08 05:00:36 +02:00
package git_commands
2021-04-10 03:40:42 +02:00
import (
"testing"
2021-12-31 01:24:53 +02:00
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
2022-01-08 04:22:29 +02:00
"github.com/jesseduffield/lazygit/pkg/config"
2021-04-10 03:40:42 +02:00
"github.com/stretchr/testify/assert"
)
2022-01-08 04:22:29 +02:00
func TestStashDrop(t *testing.T) {
2021-12-31 01:24:53 +02:00
runner := oscommands.NewFakeRunner(t).
2022-01-03 06:15:26 +02:00
ExpectGitArgs([]string{"stash", "drop", "stash@{1}"}, "", nil)
2022-01-08 04:22:29 +02:00
instance := buildStashCommands(commonDeps{runner: runner})
2021-04-10 03:40:42 +02:00
2022-01-08 04:22:29 +02:00
assert.NoError(t, instance.Drop(1))
2022-01-02 01:34:33 +02:00
runner.CheckForMissingCalls()
}
2022-01-08 04:22:29 +02:00
func TestStashApply(t *testing.T) {
2022-01-02 01:34:33 +02:00
runner := oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"stash", "apply", "stash@{1}"}, "", nil)
2022-01-08 04:22:29 +02:00
instance := buildStashCommands(commonDeps{runner: runner})
2022-01-02 01:34:33 +02:00
2022-01-08 04:22:29 +02:00
assert.NoError(t, instance.Apply(1))
2022-01-02 01:34:33 +02:00
runner.CheckForMissingCalls()
}
2022-01-08 04:22:29 +02:00
func TestStashPop(t *testing.T) {
2022-01-02 01:34:33 +02:00
runner := oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"stash", "pop", "stash@{1}"}, "", nil)
2022-01-08 04:22:29 +02:00
instance := buildStashCommands(commonDeps{runner: runner})
2022-01-02 01:34:33 +02:00
2022-01-08 04:22:29 +02:00
assert.NoError(t, instance.Pop(1))
2021-12-31 01:24:53 +02:00
runner.CheckForMissingCalls()
2021-04-10 03:40:42 +02:00
}
2022-01-08 04:22:29 +02:00
func TestStashSave(t *testing.T) {
2021-12-31 01:24:53 +02:00
runner := oscommands.NewFakeRunner(t).
2022-01-03 06:15:26 +02:00
ExpectGitArgs([]string{"stash", "save", "A stash message"}, "", nil)
2022-01-08 04:22:29 +02:00
instance := buildStashCommands(commonDeps{runner: runner})
2021-04-10 03:40:42 +02:00
2022-01-08 04:22:29 +02:00
assert.NoError(t, instance.Save("A stash message"))
2021-12-31 01:24:53 +02:00
runner.CheckForMissingCalls()
2021-04-10 03:40:42 +02:00
}
2022-01-08 04:22:29 +02:00
func TestStashStashEntryCmdObj(t *testing.T) {
type scenario struct {
testName string
index int
contextSize int
expected string
}
scenarios := []scenario{
{
testName: "Default case",
index: 5,
contextSize: 3,
expected: "git stash show -p --stat --color=always --unified=3 stash@{5}",
},
{
testName: "Show diff with custom context size",
index: 5,
contextSize: 77,
expected: "git stash show -p --stat --color=always --unified=77 stash@{5}",
},
}
for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) {
2022-01-08 04:22:29 +02:00
userConfig := config.GetDefaultConfig()
userConfig.Git.DiffContextSize = s.contextSize
instance := buildStashCommands(commonDeps{userConfig: userConfig})
cmdStr := instance.ShowStashEntryCmdObj(s.index).ToString()
assert.Equal(t, s.expected, cmdStr)
})
}
}