interoptest

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const ReportID = "0192f0a0-0000-7000-8000-000000000001"

ReportID is the fixed UUIDv7 of the deterministic tests.

Variables

View Source
var FixedNow = time.Date(2026, 10, 5, 12, 0, 0, 0, time.UTC)

FixedNow and ReportID make the importer output of the tests deterministic.

View Source
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

func CheckGolden(t *testing.T, name string, got []byte)

CheckGolden compares raw bytes (an exporter's output) with the golden file testdata/<name>; -update rewrites it.

func CompareJSON

func CompareJSON(t *testing.T, path string, v any)

CompareJSON compares v, encoded with two-space indentation and without HTML escaping, with the golden file at path; -update rewrites it.

func CompareText

func CompareText(t *testing.T, path, want string)

CompareText compares text with the file at path; -update rewrites it.

func DiffWithout

func DiffWithout(t *testing.T, want, got any, members []string) []string

DiffWithout compares two values after dropping the members (the RoundTripDiff member syntax) on both sides.

func ExportCoverage

func ExportCoverage(t *testing.T, m *engine.Mapping, out reflect.Type)

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

func FieldCoverage(t *testing.T, dir string, format importer.Format, extra ...string)

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

func Fixtures(t *testing.T, dir string) []string

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

func ImporterGolden(t *testing.T, dir string, format importer.Format)

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

func ParseFixture(t *testing.T, path string, format importer.Format) *importer.Result

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

func ParseString(t *testing.T, in string, opts importer.Options) (*importer.Result, error)

ParseString parses in through importer.Parse.

func RoundTripDiff

func RoundTripDiff(t *testing.T, want, got any, sidecar string) []string

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

func SpecOf(m *engine.Mapping) importer.Spec

SpecOf turns an import mapping into the importer spec of its format: the fields with their targets, the notes as rules.

func StructPaths

func StructPaths(t reflect.Type) []string

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 "/**".

func WantKind

func WantKind(t *testing.T, err, kind error) (line, column int)

WantKind fails unless err wraps kind and is a *importer.ParseError; it returns where the error points.

Types

type Loss

type Loss struct {
	Member string `json:"member"`
	Reason string `json:"reason"`
}

Loss is one accepted loss.

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.

func LoadVectors

func LoadVectors(t *testing.T, dir, format, version string) Vectors

LoadVectors reads the vectors.json of dir and checks it names its own format and version.

Jump to

Keyboard shortcuts

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