summaryrefslogtreecommitdiffstats
path: root/pkg/commands/git_commands/working_tree_test.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-05-19 20:18:02 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-05-20 20:54:39 +1000
commitee11046d354e167abd6b6b3b6f6fa7157ea67a31 (patch)
treeca3b42cbf95b58fc3dd05a2cff1434aef422eaae /pkg/commands/git_commands/working_tree_test.go
parent25f8b0337e1e023fd9575ecd46467810c9f49824 (diff)
Refactor interface for ApplyPatch
Diffstat (limited to 'pkg/commands/git_commands/working_tree_test.go')
-rw-r--r--pkg/commands/git_commands/working_tree_test.go56
1 files changed, 0 insertions, 56 deletions
diff --git a/pkg/commands/git_commands/working_tree_test.go b/pkg/commands/git_commands/working_tree_test.go
index ca2881efe..6d084bfbe 100644
--- a/pkg/commands/git_commands/working_tree_test.go
+++ b/pkg/commands/git_commands/working_tree_test.go
@@ -2,8 +2,6 @@ package git_commands
import (
"fmt"
- "os"
- "regexp"
"testing"
"github.com/go-errors/errors"
@@ -430,60 +428,6 @@ func TestWorkingTreeCheckoutFile(t *testing.T) {
}
}
-func TestWorkingTreeApplyPatch(t *testing.T) {
- type scenario struct {
- testName string
- runner *oscommands.FakeCmdObjRunner
- test func(error)
- }
-
- expectFn := func(regexStr string, errToReturn error) func(cmdObj oscommands.ICmdObj) (string, error) {
- return func(cmdObj oscommands.ICmdObj) (string, error) {
- re := regexp.MustCompile(regexStr)
- cmdStr := cmdObj.ToString()
- matches := re.FindStringSubmatch(cmdStr)
- assert.Equal(t, 2, len(matches), fmt.Sprintf("unexpected command: %s", cmdStr))
-
- filename := matches[1]
-
- content, err := os.ReadFile(filename)
- assert.NoError(t, err)
-
- assert.Equal(t, "test", string(content))
-
- return "", errToReturn
- }
- }
-
- scenarios := []scenario{
- {
- testName: "valid case",
- runner: oscommands.NewFakeRunner(t).
- ExpectFunc(expectFn(`git apply --cached "(.*)"`, nil)),
- test: func(err error) {
- assert.NoError(t, err)
- },
- },
- {
- testName: "command returns error",
- runner: oscommands.NewFakeRunner(t).
- ExpectFunc(expectFn(`git apply --cached "(.*)"`, errors.New("error"))),
- test: func(err error) {
- assert.Error(t, err)
- },
- },
- }
-
- for _, s := range scenarios {
- s := s
- t.Run(s.testName, func(t *testing.T) {
- instance := buildWorkingTreeCommands(commonDeps{runner: s.runner})
- s.test(instance.ApplyPatch("test", "cached"))
- s.runner.CheckForMissingCalls()
- })
- }
-}
-
func TestWorkingTreeDiscardUnstagedFileChanges(t *testing.T) {
type scenario struct {
testName string