golden

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package golden provides shared helpers for golden-file (snapshot) tests.

A golden test captures rendered output as a checked-in .golden file so the output is reviewable as a diff in PRs and regenerated on demand with -update. This package holds the generic machinery (the -update flag, ANSI stripping, file compare with a readable diff) so any command can golden its output by supplying only its own scenarios. See internal/cli/stack/sync_golden_test.go for a worked example.

Index

Constants

This section is empty.

Variables

View Source
var Update = flag.Bool("update", false, "update golden files")

Update reports whether golden files should be regenerated. Enable it with `go test ./... -update`. Go compiles each package's tests into a separate binary, so this flag is registered independently per test binary and does not collide with -update flags defined in other packages.

Functions

func Assert

func Assert(t *testing.T, path, actual string)

Assert compares actual against the golden file at path. With -update it (re)writes the file (creating parent directories) instead of comparing. On a mismatch it fails the test with a line-by-line diff; on a missing file it hints to run with -update.

func StripANSI

func StripANSI(s string) string

StripANSI removes ANSI color escape sequences so golden files stay readable and stable regardless of terminal color settings.

Types

This section is empty.

Jump to

Keyboard shortcuts

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