schematest

package
v0.9.21 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package schematest provides test helpers for comparing JSON schemas.

Use CompareReflected and CompareSubset to assert that generated schemas match expected structures, with support for subset matching to allow additional descriptive fields in the actual schema.

Package schematest provides test helpers for comparing JSON schemas.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareReflected

func CompareReflected(t *testing.T, actualJSON []byte, expectedSchema string)

CompareReflected compares a generated schema (as JSON bytes) against an expected JSON schema string. It performs a subset match — all expected properties must exist in the actual schema, but actual may have additional fields.

Example

ExampleCompareReflected demonstrates comparing a generated schema against an expected JSON schema string.

package main

import (
	"encoding/json"
	"testing"

	"chainguard.dev/driftlessaf/agents/schema"
	"chainguard.dev/driftlessaf/agents/schema/schematest"
)

func main() {
	type Input struct {
		Path string `json:"path" jsonschema:"required"`
	}

	t := &testing.T{}
	actual, _ := json.Marshal(schema.ReflectType[Input]())
	schematest.CompareReflected(t, actual, `{"type":"object"}`)
}

func CompareSubset

func CompareSubset(t *testing.T, expectedJSON string, actualJSON []byte)

CompareSubset checks that expected is a subset of actual. Both are parsed from JSON strings. This is useful for comparing tool schemas where the actual schema may contain additional descriptive fields.

Example

ExampleCompareSubset demonstrates checking that an expected schema is a subset of the actual schema.

package main

import (
	"encoding/json"
	"testing"

	"chainguard.dev/driftlessaf/agents/schema"
	"chainguard.dev/driftlessaf/agents/schema/schematest"
)

func main() {
	type Input struct {
		Path string `json:"path" jsonschema:"required"`
	}

	t := &testing.T{}
	actual, _ := json.Marshal(schema.ReflectType[Input]())
	schematest.CompareSubset(t, `{"type":"object"}`, actual)
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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