67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
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())
|
|
}
|
|
}
|
|
}
|
|
}
|