golden

package module
v0.0.0-...-aace9af Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 7 Imported by: 0

README

golden

Opinionated golden file testing.

Getting Started

Run go get github.com/elielamora/golden

add github.com/elielamora/golden to your test

Then just assert the value with golden.Assert(t, "golden"). It will pick up the file name based on the test name and represent nested tests as folder dependencies.

Run with the env var UPDATE_GOLDEN to update the golden files. Test suite will pass and you will see the new test cases as snapshots in your git diff.

TODO:

  • Automate removing orphaned golden files when tests are renamed (for now just clean up manually).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(t *testing.T, actual []byte, msgAndArgs ...any)

Assert compares the golden file to the actual data. If the golden files are being updated then it writes and always passes.

func AssertString

func AssertString(t *testing.T, actual string, msgAndArgs ...any)

AssertString compares the golden file to the actual data as a string. If the golden files are being updated then it writes and always passes.

func CutRight

func CutRight(s, sep string) (before, after string, found bool)

CutRight like strings.Cut but from the end.

func ForceUpdate

func ForceUpdate()

ForceUpdate override the golden file update behavior

func Value

func Value(t *testing.T, actual []byte) []byte

Value gets the raw data from the filesystem

Types

This section is empty.

Jump to

Keyboard shortcuts

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