diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-08 14:00:36 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-09 14:09:53 +1100 |
commit | c9a0cc6b30dca6ff6c520268c10afff4e99a68e9 (patch) | |
tree | 74a03be28aafb5fba5c8391ca611aeb25ca89445 /pkg/commands/git_commands/stash_test.go | |
parent | 3621854dc79baf2064b00b561ebea0ecc8fcb5df (diff) |
refactor
Diffstat (limited to 'pkg/commands/git_commands/stash_test.go')
-rw-r--r-- | pkg/commands/git_commands/stash_test.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go new file mode 100644 index 000000000..f9f2428e0 --- /dev/null +++ b/pkg/commands/git_commands/stash_test.go @@ -0,0 +1,80 @@ +package git_commands + +import ( + "testing" + + "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/config" + "github.com/stretchr/testify/assert" +) + +func TestStashDrop(t *testing.T) { + runner := oscommands.NewFakeRunner(t). + ExpectGitArgs([]string{"stash", "drop", "stash@{1}"}, "", nil) + instance := buildStashCommands(commonDeps{runner: runner}) + + assert.NoError(t, instance.Drop(1)) + runner.CheckForMissingCalls() +} + +func TestStashApply(t *testing.T) { + runner := oscommands.NewFakeRunner(t). + ExpectGitArgs([]string{"stash", "apply", "stash@{1}"}, "", nil) + instance := buildStashCommands(commonDeps{runner: runner}) + + assert.NoError(t, instance.Apply(1)) + runner.CheckForMissingCalls() +} + +func TestStashPop(t *testing.T) { + runner := oscommands.NewFakeRunner(t). + ExpectGitArgs([]string{"stash", "pop", "stash@{1}"}, "", nil) + instance := buildStashCommands(commonDeps{runner: runner}) + + assert.NoError(t, instance.Pop(1)) + runner.CheckForMissingCalls() +} + +func TestStashSave(t *testing.T) { + runner := oscommands.NewFakeRunner(t). + ExpectGitArgs([]string{"stash", "save", "A stash message"}, "", nil) + instance := buildStashCommands(commonDeps{runner: runner}) + + assert.NoError(t, instance.Save("A stash message")) + runner.CheckForMissingCalls() +} + +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) { + 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) + }) + } +} |