summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-05-20 16:55:07 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-05-20 16:55:15 +1000
commit63ddc52a6b0b69b656b106ee5ae74dd736ac6317 (patch)
treeb5b67588b7ba45c056b345562f9cf1ba0371eb01
parentb07c4fc0019e6432d981127019c938dcefcf808a (diff)
Increase test coverage
-rw-r--r--pkg/commands/git_commands/branch_test.go52
-rw-r--r--pkg/commands/git_commands/deps_test.go6
-rw-r--r--pkg/commands/git_commands/flow_test.go92
3 files changed, 145 insertions, 5 deletions
diff --git a/pkg/commands/git_commands/branch_test.go b/pkg/commands/git_commands/branch_test.go
index 2fdf7d9c2..75c288203 100644
--- a/pkg/commands/git_commands/branch_test.go
+++ b/pkg/commands/git_commands/branch_test.go
@@ -5,6 +5,7 @@ import (
"github.com/go-errors/errors"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
+ "github.com/jesseduffield/lazygit/pkg/config"
"github.com/stretchr/testify/assert"
)
@@ -99,12 +100,53 @@ func TestBranchDeleteBranch(t *testing.T) {
}
func TestBranchMerge(t *testing.T) {
- runner := oscommands.NewFakeRunner(t).
- Expect(`git merge --no-edit "test"`, "", nil)
- instance := buildBranchCommands(commonDeps{runner: runner})
+ scenarios := []struct {
+ testName string
+ userConfig *config.UserConfig
+ opts MergeOpts
+ branchName string
+ expected string
+ }{
+ {
+ testName: "basic",
+ userConfig: &config.UserConfig{},
+ opts: MergeOpts{},
+ branchName: "mybranch",
+ expected: `git merge --no-edit "mybranch"`,
+ },
+ {
+ testName: "merging args",
+ userConfig: &config.UserConfig{
+ Git: config.GitConfig{
+ Merging: config.MergingConfig{
+ Args: "--merging-args", // it's up to the user what they put here
+ },
+ },
+ },
+ opts: MergeOpts{},
+ branchName: "mybranch",
+ expected: `git merge --no-edit --merging-args "mybranch"`,
+ },
+ {
+ testName: "fast forward only",
+ userConfig: &config.UserConfig{},
+ opts: MergeOpts{FastForwardOnly: true},
+ branchName: "mybranch",
+ expected: `git merge --no-edit --ff-only "mybranch"`,
+ },
+ }
- assert.NoError(t, instance.Merge("test", MergeOpts{}))
- runner.CheckForMissingCalls()
+ for _, s := range scenarios {
+ s := s
+ t.Run(s.testName, func(t *testing.T) {
+ runner := oscommands.NewFakeRunner(t).
+ Expect(s.expected, "", nil)
+ instance := buildBranchCommands(commonDeps{runner: runner, userConfig: s.userConfig})
+
+ assert.NoError(t, instance.Merge(s.branchName, s.opts))
+ runner.CheckForMissingCalls()
+ })
+ }
}
func TestBranchCheckout(t *testing.T) {
diff --git a/pkg/commands/git_commands/deps_test.go b/pkg/commands/git_commands/deps_test.go
index bcf36b168..6a20c72c2 100644
--- a/pkg/commands/git_commands/deps_test.go
+++ b/pkg/commands/git_commands/deps_test.go
@@ -150,3 +150,9 @@ func buildBranchCommands(deps commonDeps) *BranchCommands {
return NewBranchCommands(gitCommon)
}
+
+func buildFlowCommands(deps commonDeps) *FlowCommands {
+ gitCommon := buildGitCommon(deps)
+
+ return NewFlowCommands(gitCommon)
+}
diff --git a/pkg/commands/git_commands/flow_test.go b/pkg/commands/git_commands/flow_test.go
new file mode 100644
index 000000000..3ee2e91a5
--- /dev/null
+++ b/pkg/commands/git_commands/flow_test.go
@@ -0,0 +1,92 @@
+package git_commands
+
+import (
+ "testing"
+
+ "github.com/jesseduffield/lazygit/pkg/commands/git_config"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestStartCmdObj(t *testing.T) {
+ scenarios := []struct {
+ testName string
+ branchType string
+ name string
+ expected string
+ }{
+ {
+ testName: "basic",
+ branchType: "feature",
+ name: "test",
+ expected: "git flow feature start test",
+ },
+ }
+
+ for _, s := range scenarios {
+ s := s
+ t.Run(s.testName, func(t *testing.T) {
+ instance := buildFlowCommands(commonDeps{})
+
+ assert.Equal(t,
+ instance.StartCmdObj(s.branchType, s.name).ToString(),
+ s.expected,
+ )
+ })
+ }
+}
+
+func TestFinishCmdObj(t *testing.T) {
+ scenarios := []struct {
+ testName string
+ branchName string
+ expected string
+ expectedError string
+ gitConfigMockResponses map[string]string
+ }{
+ {
+ testName: "not a git flow branch",
+ branchName: "mybranch",
+ expected: "",
+ expectedError: "This does not seem to be a git flow branch",
+ gitConfigMockResponses: nil,
+ },
+ {
+ testName: "feature branch without config",
+ branchName: "feature/mybranch",
+ expected: "",
+ expectedError: "This does not seem to be a git flow branch",
+ gitConfigMockResponses: nil,
+ },
+ {
+ testName: "feature branch with config",
+ branchName: "feature/mybranch",
+ expected: "git flow feature finish mybranch",
+ expectedError: "",
+ gitConfigMockResponses: map[string]string{
+ "--local --get-regexp gitflow.prefix": "gitflow.prefix.feature feature/",
+ },
+ },
+ }
+
+ for _, s := range scenarios {
+ s := s
+ t.Run(s.testName, func(t *testing.T) {
+ instance := buildFlowCommands(commonDeps{
+ gitConfig: git_config.NewFakeGitConfig(s.gitConfigMockResponses),
+ })
+
+ cmd, err := instance.FinishCmdObj(s.branchName)
+
+ if s.expectedError != "" {
+ if err == nil {
+ t.Errorf("Expected error, got nil")
+ } else {
+ assert.Equal(t, err.Error(), s.expectedError)
+ }
+ } else {
+ assert.NoError(t, err)
+ assert.Equal(t, cmd.ToString(), s.expected)
+ }
+ })
+ }
+}