2023-05-20 08:55:07 +02:00
|
|
|
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
|
2023-05-21 09:00:29 +02:00
|
|
|
expected []string
|
2023-05-20 08:55:07 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
testName: "basic",
|
|
|
|
branchType: "feature",
|
|
|
|
name: "test",
|
2023-05-21 09:00:29 +02:00
|
|
|
expected: []string{"git", "flow", "feature", "start", "test"},
|
2023-05-20 08:55:07 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range scenarios {
|
|
|
|
s := s
|
|
|
|
t.Run(s.testName, func(t *testing.T) {
|
|
|
|
instance := buildFlowCommands(commonDeps{})
|
|
|
|
|
|
|
|
assert.Equal(t,
|
2023-05-21 09:00:29 +02:00
|
|
|
instance.StartCmdObj(s.branchType, s.name).Args(),
|
2023-05-20 08:55:07 +02:00
|
|
|
s.expected,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFinishCmdObj(t *testing.T) {
|
|
|
|
scenarios := []struct {
|
|
|
|
testName string
|
|
|
|
branchName string
|
2023-05-21 09:00:29 +02:00
|
|
|
expected []string
|
2023-05-20 08:55:07 +02:00
|
|
|
expectedError string
|
|
|
|
gitConfigMockResponses map[string]string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
testName: "not a git flow branch",
|
|
|
|
branchName: "mybranch",
|
2023-05-21 09:00:29 +02:00
|
|
|
expected: nil,
|
2023-05-20 08:55:07 +02:00
|
|
|
expectedError: "This does not seem to be a git flow branch",
|
|
|
|
gitConfigMockResponses: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "feature branch without config",
|
|
|
|
branchName: "feature/mybranch",
|
2023-05-21 09:00:29 +02:00
|
|
|
expected: nil,
|
2023-05-20 08:55:07 +02:00
|
|
|
expectedError: "This does not seem to be a git flow branch",
|
|
|
|
gitConfigMockResponses: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "feature branch with config",
|
|
|
|
branchName: "feature/mybranch",
|
2023-05-21 09:00:29 +02:00
|
|
|
expected: []string{"git", "flow", "feature", "finish", "mybranch"},
|
2023-05-20 08:55:07 +02:00
|
|
|
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)
|
2023-05-21 09:00:29 +02:00
|
|
|
assert.Equal(t, cmd.Args(), s.expected)
|
2023-05-20 08:55:07 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|