Unify inline and bound schema preparation

This commit is contained in:
2026-11-20 15:31:30 +00:00
parent be5a508554
commit 2d96dfa696
7 changed files with 223 additions and 389 deletions

View File

@@ -3,6 +3,7 @@ package validate
import (
"context"
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
@@ -29,9 +30,9 @@ func TestSchemaPreparationDoesNotDependOnSourceName(t *testing.T) {
t.Fatal(err)
}
fsys := fstest.MapFS{"schema.json": &fstest.MapFile{Data: []byte(test.schema)}}
for i, validator := range []ValidationPreparer{NewStandardValidator(dir), NewFSValidator(fsys, ".")} {
for i, source := range []fs.FS{os.DirFS(dir), fsys} {
t.Run(fmt.Sprint(i), func(t *testing.T) {
_, err := validator.PrepareValidation(context.Background(), domain.OutputContract{Format: domain.FormatJSON, ValidationMode: domain.ValidationJSONSchema, SchemaPath: "schema.json"})
_, err := NewValidator().PrepareValidation(context.Background(), Input{Contract: domain.OutputContract{Format: domain.FormatJSON, ValidationMode: domain.ValidationJSONSchema, SchemaPath: "schema.json"}, File: &domain.ResourceBinding{FS: source, Path: "schema.json"}})
if test.rejected {
if err == nil || !strings.Contains(err.Error(), "source location") {
t.Fatalf("expected source-independent rejection, got %v", err)