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

contracttest

package
v0.1.0-preview.14 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package contracttest is shared by the conformance tests and the PostgreSQL tests: where the contract is, how a fixture runs, and how two JSON values are compared.

Index

Constants

This section is empty.

Variables

View Source
var (
	Contract   = filepath.Join(Repository, "contract")
	Fixtures   = filepath.Join(Contract, "fixtures")
	Schema     = filepath.Join(Contract, "schema", "experience-record.v1.json")
	Migrations = filepath.Join(Repository, "src", "AgentExperience.Storage.Postgres", "Migrations")
)

Paths into the repository.

View Source
var ErrUnsupportedContractVersion = errors.New("unsupported contract version")

ErrUnsupportedContractVersion is a lock naming a contract version this package does not support.

View Source
var Repository = func() string {
	_, file, _, ok := runtime.Caller(0)
	if !ok {
		panic("contracttest: cannot locate the repository")
	}
	return filepath.Clean(filepath.Join(filepath.Dir(file), "..", "..", ".."))
}()

Repository is the repository's root directory.

Functions

func AsWritten

func AsWritten(value any) any

AsWritten is a value as this package writes it, read back: what is compared is what the package would write.

func Cases

func Cases(family string) []string

Cases are every case directory of a fixture family, by name.

func CheckContractVersion

func CheckContractVersion(lock any) (string, error)

CheckContractVersion is the lock's contract version, when this package supports it; a clear failure otherwise.

func Difference

func Difference(expected, actual any, path string, options Options) string

Difference is the first difference between two JSON values (as ae.DecodeJSON reads them), compared by value; "" when they are equal. Member order is ignored.

func EvidenceOf

func EvidenceOf(value any) ae.Evidence

EvidenceOf reads one piece of a fixture's evidence.

func MustReadJSON

func MustReadJSON(path string) any

MustReadJSON is ReadJSON, panicking on failure: for fixtures, which are known to exist.

func ReadJSON

func ReadJSON(path string) (any, error)

ReadJSON reads a JSON file, keeping every number exactly as written and every object's member order.

func RunFinalizeCase

func RunFinalizeCase(input any) (ae.FinalizedExperience, *ae.Object, error)

RunFinalizeCase runs a finalize case's input.json through capture and finalization. It returns the result and what capture answered, in expected-capture.json's form.

func ScopeOf

func ScopeOf(value any) ae.Scope

ScopeOf reads a fixture's scope ({"tenantId", "applicationId", ...}).

Types

type Options

type Options struct {
	// Tolerance is the largest difference two numbers may have; 0 compares them exactly.
	Tolerance float64
	// IgnoreKind compares numbers by value only. By default an integer literal (no fraction, no exponent) never
	// equals a number written with a fraction or an exponent, so a double is never written as an integer or the
	// other way round. PostgreSQL's jsonb rewrites numbers in its own form (1E2 as 100), so a value read back from
	// it is compared by value only.
	IgnoreKind bool
}

Options change how Difference compares numbers.

Jump to

Keyboard shortcuts

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