diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-05-20 16:55:07 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-05-20 16:55:15 +1000 |
commit | 63ddc52a6b0b69b656b106ee5ae74dd736ac6317 (patch) | |
tree | b5b67588b7ba45c056b345562f9cf1ba0371eb01 /pkg/commands/git_commands/flow_test.go | |
parent | b07c4fc0019e6432d981127019c938dcefcf808a (diff) |
Increase test coverage
Diffstat (limited to 'pkg/commands/git_commands/flow_test.go')
-rw-r--r-- | pkg/commands/git_commands/flow_test.go | 92 |
1 files changed, 92 insertions, 0 deletions
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) + } + }) + } +} |