Help us shape the future of Go! Take the 2026 Go Developer Survey

schematest

package
v1.10.0-alpha.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package schematest runs independent JSON Schema contract checks in integration tests. Its pinned JavaScript dependencies are installed only in a test temp dir.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

type Batch struct {
	// Schema is the complete schema, including any referenced definitions.
	Schema any `json:"schema"`
	// Instances are JSON values; validation never coerces or mutates them.
	Instances []any `json:"instances"`
}

Batch pairs an emitted schema with the JSON instances to validate against it.

type Result

type Result struct {
	// Valid indicates that the schema accepted the complete instance.
	Valid bool `json:"valid"`
	// Errors contains independent validator diagnostics, empty on success.
	Errors jsontext.Value `json:"errors"`
}

Result reports acceptance and the validator's original failure diagnostics.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator owns a temporary Ajv installation with native ECMA-262 regexes.

func New

func New(t *testing.T) *Validator

New installs the locked test-only validator. Missing tools and installation failures fail the caller; an enabled contract gate can never silently skip.

func (*Validator) Check

func (v *Validator) Check(t *testing.T, batches []Batch) [][]Result

Check validates each batch in order and preserves one result per instance. Invalid schemas and protocol/tool failures fail the caller independently of ordinary instance rejection.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL