Migrate validator tests to prepared plans
This commit is contained in:
@@ -240,14 +240,6 @@ type fakeValidator struct {
|
||||
validateCalls int
|
||||
}
|
||||
|
||||
func (f *fakeValidator) Validate(ctx context.Context, artifact *domain.Artifact, contract domain.OutputContract) (domain.ValidationResult, error) {
|
||||
f.validateCalls++
|
||||
if f.err != nil {
|
||||
return domain.ValidationResult{}, f.err
|
||||
}
|
||||
return f.result, nil
|
||||
}
|
||||
|
||||
func (f *fakeValidator) PrepareValidation(_ context.Context, contract domain.OutputContract) (validate.PreparedValidation, error) {
|
||||
var schemaDocument any
|
||||
if contract.ValidationMode == domain.ValidationJSONSchema {
|
||||
@@ -261,17 +253,20 @@ func (f *fakeValidator) PrepareValidation(_ context.Context, contract domain.Out
|
||||
schemaDocument = map[string]any{"type": "object"}
|
||||
}
|
||||
}
|
||||
return &fakePreparedValidator{validator: f, contract: contract, schemaDocument: schemaDocument}, nil
|
||||
return &fakePreparedValidator{validator: f, schemaDocument: schemaDocument}, nil
|
||||
}
|
||||
|
||||
type fakePreparedValidator struct {
|
||||
validator *fakeValidator
|
||||
contract domain.OutputContract
|
||||
schemaDocument any
|
||||
}
|
||||
|
||||
func (p *fakePreparedValidator) Validate(ctx context.Context, artifact *domain.Artifact) (domain.ValidationResult, error) {
|
||||
return p.validator.Validate(ctx, artifact, p.contract)
|
||||
p.validator.validateCalls++
|
||||
if p.validator.err != nil {
|
||||
return domain.ValidationResult{}, p.validator.err
|
||||
}
|
||||
return p.validator.result, nil
|
||||
}
|
||||
|
||||
func (p *fakePreparedValidator) SchemaDocument() any {
|
||||
|
||||
Reference in New Issue
Block a user