golden

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package golden provides utilities to compare and update golden files in tests.

Index

Constants

View Source
const (
	// UpdateGoldenFilesEnv is the environment variable used to indicate go test that
	// the golden files should be overwritten with the current test results.
	UpdateGoldenFilesEnv = `TESTS_UPDATE_GOLDEN`
)

Variables

This section is empty.

Functions

func CheckOrUpdate

func CheckOrUpdate(t *testing.T, got string, options ...Option)

CheckOrUpdate compares the provided string with the content of the golden file. If the update environment variable is set, the golden file is updated with the provided string.

func CheckOrUpdateFileTree

func CheckOrUpdateFileTree(t *testing.T, path string, options ...Option)

CheckOrUpdateFileTree allows comparing a goldPath directory to p. Those can be updated via the dedicated flag.

func CheckOrUpdateYAML

func CheckOrUpdateYAML[E any](t *testing.T, got E, options ...Option)

CheckOrUpdateYAML compares the provided object with the content of the golden file. If the update environment variable is set, the golden file is updated with the provided object serialized as YAML.

func CheckValidGoldenFileName

func CheckValidGoldenFileName(t *testing.T, name string)

CheckValidGoldenFileName checks if the provided name is a valid golden file name.

func LoadWithUpdate

func LoadWithUpdate(t *testing.T, data string, options ...Option) string

LoadWithUpdate loads the element from a plaintext golden file. It will update the file if the update flag is used prior to loading it.

func LoadWithUpdateYAML

func LoadWithUpdateYAML[E any](t *testing.T, got E, options ...Option) E

LoadWithUpdateYAML load the generic element from a YAML serialized golden file. It will update the file if the update flag is used prior to deserializing it.

func Path

func Path(t *testing.T) string

Path returns the golden path for the provided test.

func UpdateEnabled

func UpdateEnabled() bool

UpdateEnabled returns true if the update flag was set, false otherwise.

Types

type Option

type Option func(*goldenOptions)

Option is a supported option reference to change the golden files comparison.

func WithPath

func WithPath(path string) Option

WithPath overrides the default path for golden files used.

Jump to

Keyboard shortcuts

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