golden

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: MIT Imports: 8 Imported by: 0

README

Go Reference Build Status

golden

Golden test file utility.

Golden provides a simple, opinionated API for managing golden test files. See the golden_test.go and testdata directory for examples.

Use

package module_test

import (
 "testing"

 "github.com/dcilke/golden"
)

func Test(t *testing.T) {
  actual := functionUnderTest()
  golden.Assert(t, actual)
}

Features

  • Automatic golden file management. All golden files are stored next to tests in testdata/golden.
  • Automatic naming of golden files. Golden files are named after the test function.See golden.Subsert() if multiple asserts are needed in the same test.
  • Automatic creating golden files if none are present. Golden files can be regenerated by setting the GOLDEN_UPDATE environment variable to true.
  • Golden files are serialized with litter to provide clear output and human readable diffs.

Documentation

Index

Constants

View Source
const (
	EnvUpdate = "GOLDEN_UPDATE"
)

Variables

This section is empty.

Functions

func Assert

func Assert(t testing.TB, actual any)

Assert asserts the value for the given test

func AssertFunc

func AssertFunc(t testing.TB, name string, actual any, a Asserter)

AssertFunc fetches the test data from the golden directory, updating as necessary, and then calls the Asserter to compare the values

func Subsert

func Subsert(t testing.TB, name string, actual any)

Subsert asserts on a sub assertion a test

func ToBytes

func ToBytes(t testing.TB, actual any) []byte

func Update

func Update(t testing.TB, file string, data []byte)

Update updates the golden file

Types

type Asserter

type Asserter func(t testing.TB, expected []byte, actual any)

Jump to

Keyboard shortcuts

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