1

add: import code

портирован код из старого репозитория https://di9.ru/git/Voomra/Conventional-Commits
This commit is contained in:
2025-07-30 18:44:50 +03:00
commit af99bebf91
16 changed files with 575 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
package configuration
import (
"github.com/stretchr/testify/assert"
"os"
"regexp"
"testing"
)
func TestReadUserConfig(t *testing.T) {
createTmpJson := func() string {
tmpFile, err := os.CreateTemp("", "config.json")
if err != nil {
panic(err)
}
defer func(tmpFile *os.File) {
_ = tmpFile.Close()
}(tmpFile)
_, err = tmpFile.WriteString(`{"types": ["type1", "type2"], "contexts": ["ctx1", "ctx2"], "excludes": ["^wip$"], "maxLengthLine": 14}`)
if err != nil {
panic(err)
}
return tmpFile.Name()
}
expectedUserConfig := UserConfig{}
expectedUserConfig.Types = &([]string{"type1", "type2"})
expectedUserConfig.Contexts = &([]string{"ctx1", "ctx2"})
expectedUserConfig.Excludes = &([]string{"^wip$"})
expectedUserConfig.MaxLengthLine = new(int)
*(expectedUserConfig.MaxLengthLine) = 14
userConfig, err := readUserConfig(createTmpJson())
if err != nil {
panic(err)
}
assert.Equal(t, expectedUserConfig, *userConfig)
}
func TestMergeConfigs(t *testing.T) {
config := Config{
Types: []string{"fix", "feat"},
Contexts: []string{},
Excludes: []*regexp.Regexp{},
MaxLengthLine: 72,
}
userConfig := UserConfig{}
userConfig.Types = &([]string{"type1", "type2"})
userConfig.Contexts = &([]string{"ctx1", "ctx2"})
userConfig.Excludes = &([]string{"^wip$"})
userConfig.MaxLengthLine = new(int)
*(userConfig.MaxLengthLine) = 14
expectedConfig := Config{
Types: []string{"fix", "feat", "type1", "type2"},
Contexts: []string{"ctx1", "ctx2"},
Excludes: []*regexp.Regexp{},
MaxLengthLine: 14,
}
expectedConfig.Excludes = append(expectedConfig.Excludes, regexp.MustCompile("^wip$"))
mergeConfigs(&config, &userConfig)
assert.Equal(t, expectedConfig, config)
}