diff options
Diffstat (limited to 'pkg/commands/git_test.go')
-rw-r--r-- | pkg/commands/git_test.go | 103 |
1 files changed, 101 insertions, 2 deletions
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index 614ad527b..aa1785af8 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -1933,8 +1933,8 @@ func TestGitCommandGetCommitFiles(t *testing.T) { } } -// TestGitCommandDiscardUnstagedChanges is a function. -func TestGitCommandDiscardUnstagedChanges(t *testing.T) { +// TestGitCommandDiscardUnstagedFileChanges is a function. +func TestGitCommandDiscardUnstagedFileChanges(t *testing.T) { type scenario struct { testName string file *File @@ -1967,3 +1967,102 @@ func TestGitCommandDiscardUnstagedChanges(t *testing.T) { }) } } + +// TestGitCommandDiscardAnyUnstagedFileChanges is a function. +func TestGitCommandDiscardAnyUnstagedFileChanges(t *testing.T) { + type scenario struct { + testName string + command func(string, ...string) *exec.Cmd + test func(error) + } + + scenarios := []scenario{ + { + "valid case", + test.CreateMockCommand(t, []*test.CommandSwapper{ + { + Expect: `git checkout -- .`, + Replace: "echo", + }, + }), + func(err error) { + assert.NoError(t, err) + }, + }, + } + + gitCmd := NewDummyGitCommand() + + for _, s := range scenarios { + t.Run(s.testName, func(t *testing.T) { + gitCmd.OSCommand.command = s.command + s.test(gitCmd.DiscardAnyUnstagedFileChanges()) + }) + } +} + +// TestGitCommandRemoveUntrackedFiles is a function. +func TestGitCommandRemoveUntrackedFiles(t *testing.T) { + type scenario struct { + testName string + command func(string, ...string) *exec.Cmd + test func(error) + } + + scenarios := []scenario{ + { + "valid case", + test.CreateMockCommand(t, []*test.CommandSwapper{ + { + Expect: `git clean -fd`, + Replace: "echo", + }, + }), + func(err error) { + assert.NoError(t, err) + }, + }, + } + + gitCmd := NewDummyGitCommand() + + for _, s := range scenarios { + t.Run(s.testName, func(t *testing.T) { + gitCmd.OSCommand.command = s.command + s.test(gitCmd.RemoveUntrackedFiles()) + }) + } +} + +// TestGitCommandResetHardHead is a function. +func TestGitCommandResetHardHead(t *testing.T) { + type scenario struct { + testName string + command func(string, ...string) *exec.Cmd + test func(error) + } + + scenarios := []scenario{ + { + "valid case", + test.CreateMockCommand(t, []*test.CommandSwapper{ + { + Expect: `git reset --hard HEAD`, + Replace: "echo", + }, + }), + func(err error) { + assert.NoError(t, err) + }, + }, + } + + gitCmd := NewDummyGitCommand() + + for _, s := range scenarios { + t.Run(s.testName, func(t *testing.T) { + gitCmd.OSCommand.command = s.command + s.test(gitCmd.ResetHardHead()) + }) + } +} |