Documentation
¶
Overview ¶
Package interoptest holds the test helpers the interoperability adapters (v2/interop/<format>, nested modules of this repository) share: golden files, round-trip comparison with declared losses, field coverage of mapping files. It is internal and only imported by tests.
Index ¶
- Constants
- Variables
- func CheckGolden(t *testing.T, name string, got []byte)
- func CompareJSON(t *testing.T, path string, v any)
- func CompareText(t *testing.T, path, want string)
- func DiffWithout(t *testing.T, want, got any, members []string) []string
- func ExportCoverage(t *testing.T, m *engine.Mapping, out reflect.Type)
- func ExportVectors(t *testing.T, dir, format, version string, ...)
- func FieldCoverage(t *testing.T, dir string, format importer.Format, extra ...string)
- func Fixtures(t *testing.T, dir string) []string
- func ImportVectors(t *testing.T, dir string, format importer.Format, version string, ns string, ...)
- func ImporterGolden(t *testing.T, dir string, format importer.Format)
- func ParseFixture(t *testing.T, path string, format importer.Format) *importer.Result
- func ParseString(t *testing.T, in string, opts importer.Options) (*importer.Result, error)
- func RoundTripDiff(t *testing.T, want, got any, sidecar string) []string
- func SpecOf(m *engine.Mapping) importer.Spec
- func StructPaths(t reflect.Type) []string
- func WantKind(t *testing.T, err, kind error) (line, column int)
- type Loss
- type Vector
- type Vectors
Constants ¶
const ReportID = "0192f0a0-0000-7000-8000-000000000001"
ReportID is the fixed UUIDv7 of the deterministic tests.
Variables ¶
var FixedNow = time.Date(2026, 10, 5, 12, 0, 0, 0, time.UTC)
FixedNow and ReportID make the importer output of the tests deterministic.
var Update = flag.Bool("update", false, "rewrite the golden files")
Update is the -update flag of the adapters' tests: rewrite the golden files instead of comparing.
Functions ¶
func CheckGolden ¶
CheckGolden compares raw bytes (an exporter's output) with the golden file testdata/<name>; -update rewrites it.
func CompareJSON ¶
CompareJSON compares v, encoded with two-space indentation and without HTML escaping, with the golden file at path; -update rewrites it.
func CompareText ¶
CompareText compares text with the file at path; -update rewrites it.
func DiffWithout ¶
DiffWithout compares two values after dropping the members (the RoundTripDiff member syntax) on both sides.
func ExportCoverage ¶
ExportCoverage checks that the export mapping lists every path the output type can hold: the mapping is the complete list of what the exporter writes, and Reemit never writes into those places.
func ExportVectors ¶
func ExportVectors(t *testing.T, dir, format, version string, export func(*ctis.Report) ([]byte, error))
ExportVectors runs export-only vectors: a CTIS document to the golden upstream document.
func FieldCoverage ¶
FieldCoverage is the mapping discipline gate of an import mapping: every source field of every fixture of dir is listed in the format's spec (mapped or ignored on purpose), and every mapped field of the spec occurs in a fixture, so the golden files prove each mapping the spec claims. extra are more source paths that prove fields (other test inputs).
func Fixtures ¶
Fixtures lists the input fixtures of dir: every file that is not a golden file or a sidecar.
func ImportVectors ¶
func ImportVectors(t *testing.T, dir string, format importer.Format, version string, ns string, export func(*ctis.Report) ([]byte, error))
ImportVectors runs the import vectors of dir through importer.Parse (the adapter is registered), and, when export is not nil, the round trips.
func ImporterGolden ¶
ImporterGolden pins the CTIS output of every fixture of dir (report in <stem>.golden.json, the rest in <stem>.result.json) and checks that it is a valid report whose findings all resolve to an asset.
func ParseFixture ¶
ParseFixture parses a fixture through importer.Parse with the fixed clock and report id; <stem>.options.json sets the repository a code report is filed on. Observe is on, so Result.Fields lists the source paths.
func ParseString ¶
ParseString parses in through importer.Parse.
func RoundTripDiff ¶
RoundTripDiff compares two reports (or any JSON values) after dropping the accepted losses listed in the sidecar file (relative to testdata/export; "" for none) and reports the differing paths.
func SpecOf ¶
SpecOf turns an import mapping into the importer spec of its format: the fields with their targets, the notes as rules.
func StructPaths ¶
StructPaths lists the JSON paths an encoded value of type t can hold, in the field path syntax: maps as "/*", slices as "[]", an any or raw value as "/**".
Types ¶
type Vector ¶
type Vector struct {
Name string `json:"name"`
// Input is the upstream sample (import vectors) or a CTIS document
// (export-only vectors).
Input string `json:"input"`
// Expect is the golden output: the CTIS report of an import (with the
// VEX statements a VEX document gives), the upstream document of an
// export-only vector.
Expect string `json:"expect"`
// RoundTrip: import, export, import again; the two reports are equal
// but for Losses.
RoundTrip bool `json:"roundtrip,omitempty"`
// Losses are the accepted losses of the round trip, each with a reason.
Losses []Loss `json:"losses,omitempty"`
// Reemitted are pointers into the input that the export writes back
// with the same value (the passthrough).
Reemitted []string `json:"reemitted,omitempty"`
// Kept are pointers (as stored under extensions) that the import keeps
// as passthrough.
Kept []string `json:"kept,omitempty"`
// Never are strings that must not appear anywhere in the report nor in
// the export (raw secrets, command lines, script URLs).
Never []string `json:"never,omitempty"`
}
Vector is one upstream sample document (import) or one CTIS document (export) and what must hold for it.
type Vectors ¶
type Vectors struct {
Format string `json:"format"`
Version string `json:"version"`
Vectors []Vector `json:"vectors"`
}
Vectors are the conformance vectors of one adapter and upstream version: conformance/interop/<format>/<version>/vectors.json and the files it names. Every implementation of an adapter runs the same files.