40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package alwaysreject
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
|
)
|
|
|
|
func TestValidatorRejects(t *testing.T) {
|
|
result, err := NewTyped[string](Options{}).Validate(context.Background(), contracts.TypedValidationRequest[string]{Value: "value"})
|
|
if err != nil {
|
|
t.Fatalf("Validate() error = %v, want nil", err)
|
|
}
|
|
if result.Approved {
|
|
t.Fatalf("Approved = true, want false")
|
|
}
|
|
if result.ReasonCode != ReasonCode {
|
|
t.Fatalf("ReasonCode = %q, want %q", result.ReasonCode, ReasonCode)
|
|
}
|
|
if result.Message == "" {
|
|
t.Fatal("Message = empty, want rejection message")
|
|
}
|
|
}
|
|
|
|
func TestSpecAndRegister(t *testing.T) {
|
|
if Spec().Key != Key || Spec().ExecutionClass != contracts.ExecutionClassDeterministic {
|
|
t.Fatalf("Spec() = %#v, want key and deterministic execution", Spec())
|
|
}
|
|
|
|
registry := pipeline.NewValidatorRegistry()
|
|
if err := Register(registry); err != nil {
|
|
t.Fatalf("Register() error = %v, want nil", err)
|
|
}
|
|
if registered, ok := registry.Spec(Key); !ok || registered.Key != Key {
|
|
t.Fatalf("Spec(%q) = %#v, %v", Key, registered, ok)
|
|
}
|
|
}
|