59 lines
1.9 KiB
Go
59 lines
1.9 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
|
)
|
|
|
|
func TestValidatorRegistryBehavior(t *testing.T) {
|
|
runRegistryBehaviorTests(t, registryBehaviorCase[contracts.Validator]{
|
|
name: "ValidatorRegistry",
|
|
key: "generic-validator",
|
|
stage: StageValidate,
|
|
wrongStage: StageExtract,
|
|
newRegistry: func() any {
|
|
return NewValidatorRegistry()
|
|
},
|
|
register: func(registry any, key string, constructor func() (contracts.Validator, error)) error {
|
|
return registry.(*ValidatorRegistry).Register(key, constructor)
|
|
},
|
|
registerWithSpec: func(registry any, spec ModuleSpec, constructor func() (contracts.Validator, error)) error {
|
|
return registry.(*ValidatorRegistry).RegisterWithSpec(spec, constructor)
|
|
},
|
|
build: func(registry any, key string) (contracts.Validator, error) {
|
|
return registry.(*ValidatorRegistry).Build(key)
|
|
},
|
|
spec: func(registry any, key string) (ModuleSpec, bool) {
|
|
return registry.(*ValidatorRegistry).Spec(key)
|
|
},
|
|
registeredKeys: func(registry any) []string {
|
|
return registry.(*ValidatorRegistry).RegisteredKeys()
|
|
},
|
|
nilRegister: func(key string, constructor func() (contracts.Validator, error)) error {
|
|
var registry *ValidatorRegistry
|
|
return registry.Register(key, constructor)
|
|
},
|
|
nilBuild: func(key string) (contracts.Validator, error) {
|
|
var registry *ValidatorRegistry
|
|
return registry.Build(key)
|
|
},
|
|
nilSpec: func(key string) (ModuleSpec, bool) {
|
|
var registry *ValidatorRegistry
|
|
return registry.Spec(key)
|
|
},
|
|
nilRegisteredKey: func() []string {
|
|
var registry *ValidatorRegistry
|
|
return registry.RegisteredKeys()
|
|
},
|
|
constructor: func(key string) func() (contracts.Validator, error) {
|
|
return func() (contracts.Validator, error) {
|
|
return registryValidator{name: key}, nil
|
|
}
|
|
},
|
|
moduleKey: func(module contracts.Validator) string {
|
|
return module.Name()
|
|
},
|
|
})
|
|
}
|