mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 20:36:03 +02:00
This implementation, unlike that proposed in https://github.com/jesseduffield/lazygit/pull/4253 keeps the yaml schema easy, and does a migration from the single elements to a sequence of elements.
78 lines
1.5 KiB
Go
78 lines
1.5 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func TestCommitPrefixMigrations(t *testing.T) {
|
|
scenarios := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{
|
|
"Empty String",
|
|
"",
|
|
"",
|
|
}, {
|
|
"Single CommitPrefix Rename",
|
|
`
|
|
git:
|
|
commitPrefix:
|
|
pattern: "^\\w+-\\w+.*"
|
|
replace: '[JIRA $0] '`,
|
|
`
|
|
git:
|
|
commitPrefix:
|
|
- pattern: "^\\w+-\\w+.*"
|
|
replace: '[JIRA $0] '`,
|
|
}, {
|
|
"Complicated CommitPrefixes Rename",
|
|
`
|
|
git:
|
|
commitPrefixes:
|
|
foo:
|
|
pattern: "^\\w+-\\w+.*"
|
|
replace: '[OTHER $0] '
|
|
CrazyName!@#$^*&)_-)[[}{f{[]:
|
|
pattern: "^foo.bar*"
|
|
replace: '[FUN $0] '`,
|
|
`
|
|
git:
|
|
commitPrefixes:
|
|
foo:
|
|
- pattern: "^\\w+-\\w+.*"
|
|
replace: '[OTHER $0] '
|
|
CrazyName!@#$^*&)_-)[[}{f{[]:
|
|
- pattern: "^foo.bar*"
|
|
replace: '[FUN $0] '`,
|
|
}, {
|
|
"Incomplete Configuration",
|
|
"git:",
|
|
"git:",
|
|
},
|
|
}
|
|
|
|
for _, s := range scenarios {
|
|
t.Run(s.name, func(t *testing.T) {
|
|
expectedConfig := GetDefaultConfig()
|
|
err := yaml.Unmarshal([]byte(s.expected), expectedConfig)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
actual, err := computeMigratedConfig("path doesn't matter", []byte(s.input))
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
actualConfig := GetDefaultConfig()
|
|
err = yaml.Unmarshal(actual, actualConfig)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
assert.Equal(t, expectedConfig, actualConfig)
|
|
})
|
|
}
|
|
}
|