mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-25 12:24:47 +02:00
Increase test coverage
This commit is contained in:
parent
b07c4fc001
commit
63ddc52a6b
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -99,12 +100,53 @@ func TestBranchDeleteBranch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBranchMerge(t *testing.T) {
|
func TestBranchMerge(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
scenarios := []struct {
|
||||||
Expect(`git merge --no-edit "test"`, "", nil)
|
testName string
|
||||||
instance := buildBranchCommands(commonDeps{runner: runner})
|
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{}))
|
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()
|
runner.CheckForMissingCalls()
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBranchCheckout(t *testing.T) {
|
func TestBranchCheckout(t *testing.T) {
|
||||||
|
@ -150,3 +150,9 @@ func buildBranchCommands(deps commonDeps) *BranchCommands {
|
|||||||
|
|
||||||
return NewBranchCommands(gitCommon)
|
return NewBranchCommands(gitCommon)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildFlowCommands(deps commonDeps) *FlowCommands {
|
||||||
|
gitCommon := buildGitCommon(deps)
|
||||||
|
|
||||||
|
return NewFlowCommands(gitCommon)
|
||||||
|
}
|
||||||
|
92
pkg/commands/git_commands/flow_test.go
Normal file
92
pkg/commands/git_commands/flow_test.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user