golden

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package golden will contain some utility functions for golden file testing

Golden File Testing pattern explained here:

https://ieftimov.com/posts/testing-in-go-golden-files/

PopulateGoldenFiles will need to be added to the first test run and then removed

Golden Files are populated and asserted based on the current runs test name t should be of a type *testing.T ref:[https://pkg.go.dev/testing#T] TODO this package has many limitations, e.g. only works with JSON and Structs, and it's not currently used by anyone.

Consider to remove it or improve it

Index

Constants

View Source
const (
	MarshalPrefix = ""
	MarshalIndent = "    "
)

Variables

This section is empty.

Functions

func Assert

func Assert(t GoldenFileTestingT, data interface{})

Assert will assert that the data matches what is in the golden file. data should be of a type struct and not []byte or string. The function will marshal the data into JSON. The diff will be represented in a colored diff

func GetGoldenFilePath

func GetGoldenFilePath(t GoldenFileTestingT) string

GetGoldenFilePath will typically return the path in the form ./testdata/golden/<sub-test-name>/<table_driven_test_name>.json However, if the test is not run in a subtest or table driven test, the path may differ. However, the last portion of the path will always become the golden json name.

func PopulateGoldenFiles

func PopulateGoldenFiles(t GoldenFileTestingT, data interface{})

PopulateGoldenFiles will write golden files to the according path returned from the GetGoldenFilePath function. The function will marshal the data into JSON. data should be of a type struct and not []byte or string. TODO review this function: if the function fails the test at beginning, what's the point to have it?

Types

type GoldenFileTestingT

type GoldenFileTestingT interface {
	Fatalf(format string, args ...any)
	Errorf(format string, args ...any)
	Name() string
}

Jump to

Keyboard shortcuts

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