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 ¶
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"}`)
}
Output:
func CompareSubset ¶
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)
}
Output:
Types ¶
This section is empty.