Change TestCommitPrefixMigrations to compare only strings

This commit is contained in:
Stefan Haller 2025-02-23 18:51:35 +01:00
parent 4b30bc6dd3
commit 38ab7ebefb

View file

@ -4,7 +4,6 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
func TestCommitPrefixMigrations(t *testing.T) {
@ -19,36 +18,36 @@ func TestCommitPrefixMigrations(t *testing.T) {
expected: "",
}, {
name: "Single CommitPrefix Rename",
input: `
git:
input: `git:
commitPrefix:
pattern: "^\\w+-\\w+.*"
replace: '[JIRA $0] '`,
expected: `
git:
replace: '[JIRA $0] '
`,
expected: `git:
commitPrefix:
- pattern: "^\\w+-\\w+.*"
replace: '[JIRA $0] '`,
replace: '[JIRA $0] '
`,
}, {
name: "Complicated CommitPrefixes Rename",
input: `
git:
input: `git:
commitPrefixes:
foo:
pattern: "^\\w+-\\w+.*"
replace: '[OTHER $0] '
CrazyName!@#$^*&)_-)[[}{f{[]:
pattern: "^foo.bar*"
replace: '[FUN $0] '`,
expected: `
git:
replace: '[FUN $0] '
`,
expected: `git:
commitPrefixes:
foo:
- pattern: "^\\w+-\\w+.*"
replace: '[OTHER $0] '
CrazyName!@#$^*&)_-)[[}{f{[]:
- pattern: "^foo.bar*"
replace: '[FUN $0] '`,
foo:
- pattern: "^\\w+-\\w+.*"
replace: '[OTHER $0] '
CrazyName!@#$^*&)_-)[[}{f{[]:
- pattern: "^foo.bar*"
replace: '[FUN $0] '
`,
}, {
name: "Incomplete Configuration",
input: "git:",
@ -58,21 +57,11 @@ 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)
assert.Equal(t, s.expected, string(actual))
})
}
}