1
This repository has been archived on 2025-08-19. You can view files and clone it, but cannot push or open issues or pull requests.
Files
go-commitlint/internal/commitlint/configuration/config_test.go
Voomra af99bebf91 add: import code
портирован код из старого репозитория https://di9.ru/git/Voomra/Conventional-Commits
2025-07-30 18:44:50 +03:00

70 lines
1.7 KiB
Go

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)
}