fixture

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertCoverage

func AssertCoverage(t *testing.T, area string)

AssertCoverage validates the layout and common metadata of every case in an area. Subsystem tests remain responsible for interpreting kind-specific data.

func Expand

func Expand(data []byte, paths Paths) []byte

Expand replaces ${HOME}, ${WORKDIR}, and ${CONFIG_DIR} in one non-recursive pass. Other placeholders are fixture content and remain unchanged.

func RegisterRunner

func RegisterRunner(area, runner string, kinds ...string)

RegisterRunner declares the exact fixture kinds executed by a named test runner. A zero-kind registration is dormant and owns no fixture cases.

func Run

func Run(m *testing.M) int

Run executes a package test binary and verifies its registered fixture runners before returning the process exit code.

func UpdatePack

func UpdatePack(root string) error

UpdatePack regenerates the language-neutral fixture archive and manifest.

func VerifyPack

func VerifyPack(root string) error

VerifyPack compares the committed fixture archive and manifest without mutating either the fixtures or their generated artifacts.

func Walk

func Walk(t *testing.T, area, runner string, run func(*testing.T, Case))

func WalkKinds

func WalkKinds(t *testing.T, area, runner string, kinds []string, run func(*testing.T, Case))

WalkKinds runs only cases whose case.json kind is selected.

Types

type Case

type Case struct {
	Area string
	ID   string
	Dir  string
	// contains filtered or unexported fields
}

func (Case) CompareJSON

func (c Case) CompareJSON(t *testing.T, name string, actual any, paths Paths, mode GoldenMode)

CompareJSON structurally compares actual with a JSON golden. GoldenUpdate atomically replaces the golden with deterministic, placeholder-normalized JSON before performing the same read-only comparison.

func (Case) Decode

func (c Case) Decode(t *testing.T, name string, destination any)

func (Case) DecodePaths

func (c Case) DecodePaths(t *testing.T, name string, destination any, paths Paths)

DecodePaths loads sorted JSON, expands placeholders in JSON string values, and decodes it into destination.

func (Case) Metadata

func (c Case) Metadata(t *testing.T) Metadata

Metadata loads and validates the common fixture metadata.

func (Case) Read

func (c Case) Read(t *testing.T, name string, paths Paths) []byte

Read loads a fixture file and expands portable path placeholders once.

type GoldenMode

type GoldenMode uint8

GoldenMode makes golden-file mutation an explicit call-site decision.

const (
	GoldenReadOnly GoldenMode = iota
	GoldenUpdate
)

type Metadata

type Metadata struct {
	Area string `json:"area"`
	ID   string `json:"id"`
	Kind string `json:"kind"`
}

Metadata is the common portion of every case.json file.

type Paths

type Paths struct {
	Home      string
	WorkDir   string
	ConfigDir string
}

Paths contains the only values that portable fixtures may substitute. Values are normalized to slash-separated paths before use.

type WarningFields

type WarningFields struct {
	Code   string `json:"code"`
	Source string `json:"source"`
	Path   string `json:"path"`
	Line   int    `json:"line"`
}

WarningFields is the stable fixture projection of a warning. Human-readable messages are deliberately excluded from golden compatibility.

func StableWarnings

func StableWarnings(values []warning.Warning) []WarningFields

StableWarnings removes warning prose while retaining stable structured fields in producer order. Paths use slash separators, and an empty input projects to [] rather than null.

Directories

Path Synopsis
cmd
fixturepack command

Jump to

Keyboard shortcuts

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