Refactor validators into built-in registry chains
This commit is contained in:
66
internal/validators/module_chains_test.go
Normal file
66
internal/validators/module_chains_test.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package validators_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/modules/glossary"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/modules/grammar"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/modules/homophones"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/modules/spoken_word"
|
||||
builtinvalidators "gitea.maximumdirect.net/eric/audita/internal/validators"
|
||||
)
|
||||
|
||||
func TestProductionModulesUseRegisteredValidatorKeys(t *testing.T) {
|
||||
registry := builtinvalidators.NewBuiltInRegistry()
|
||||
keys := map[string]struct{}{}
|
||||
for _, key := range registry.RegisteredKeys() {
|
||||
keys[key] = struct{}{}
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
build func() ([]contracts.Validator, error)
|
||||
}{
|
||||
{name: "glossary", build: func() ([]contracts.Validator, error) {
|
||||
m, err := glossary.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m.Validators(), nil
|
||||
}},
|
||||
{name: "homophones", build: func() ([]contracts.Validator, error) {
|
||||
m, err := homophones.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m.Validators(), nil
|
||||
}},
|
||||
{name: "spoken_word", build: func() ([]contracts.Validator, error) {
|
||||
m, err := spoken_word.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m.Validators(), nil
|
||||
}},
|
||||
{name: "grammar", build: func() ([]contracts.Validator, error) {
|
||||
m, err := grammar.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m.Validators(), nil
|
||||
}},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
validators, err := tc.build()
|
||||
if err != nil {
|
||||
t.Fatalf("build module %s: %v", tc.name, err)
|
||||
}
|
||||
for _, v := range validators {
|
||||
if _, ok := keys[v.Name()]; !ok {
|
||||
t.Fatalf("module %s uses unregistered validator key %q", tc.name, v.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user