add: import code
портирован код из старого репозитория https://di9.ru/git/Voomra/Conventional-Commits
This commit is contained in:
83
internal/commitlint/validator/validator_test.go
Normal file
83
internal/commitlint/validator/validator_test.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"commitlint/internal/commitlint/configuration"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateFirstLine(t *testing.T) {
|
||||
pConfig, err := configuration.CreateConfig(nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
pConfig.Contexts = append(pConfig.Contexts, "git")
|
||||
pConfig.Excludes = append(pConfig.Excludes, regexp.MustCompile("(?i)^wip$"))
|
||||
|
||||
testTab := []struct {
|
||||
line string
|
||||
excepted *ValidateError
|
||||
}{
|
||||
{
|
||||
line: "incorrect line",
|
||||
excepted: &ValidateError{Result: IncorrectPattern, Line: 1},
|
||||
},
|
||||
{
|
||||
line: "zed: message",
|
||||
excepted: &ValidateError{Result: UnknownType, Line: 1, UnknownType: "zed"},
|
||||
},
|
||||
{
|
||||
line: "fix(zed): message",
|
||||
excepted: &ValidateError{Result: UnknownContext, Line: 1, UnknownContext: "zed"},
|
||||
},
|
||||
{
|
||||
line: "fix: message",
|
||||
excepted: nil,
|
||||
},
|
||||
{
|
||||
line: "fix(git): message",
|
||||
excepted: nil,
|
||||
},
|
||||
{
|
||||
line: "WIP",
|
||||
excepted: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testTab {
|
||||
pResult := validateFirstLine(test.line, *pConfig)
|
||||
assert.Equal(t, test.excepted, pResult)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateBody(t *testing.T) {
|
||||
pConfig, err := configuration.CreateConfig(nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
pConfig.MaxLengthLine = 10
|
||||
|
||||
testTab := []struct {
|
||||
lines []string
|
||||
excepted *ValidateError
|
||||
}{
|
||||
{
|
||||
lines: []string{" ", "Some Body"},
|
||||
excepted: &ValidateError{Result: BlankLine, Line: 2},
|
||||
},
|
||||
{
|
||||
lines: []string{"", "Some Body 1234567890"},
|
||||
excepted: &ValidateError{Result: OverlongLine, Line: 3},
|
||||
},
|
||||
{
|
||||
lines: []string{"", "Some Body"},
|
||||
excepted: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testTab {
|
||||
pResult := validateBody(test.lines, *pConfig)
|
||||
assert.Equal(t, test.excepted, pResult)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user