gold

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formats

type Formats func(reader io.Reader, writer io.Writer) error

Formats is an alias for function signature that reads from reader, formats it and writes to writer.

type Gold

type Gold struct {
	// contains filtered or unexported fields
}

Gold makes assertions against golden files.

func New

func New(t Testing, options ...Option) *Gold

New initializes an instance of Gold.

func (*Gold) AssertEquals

func (g *Gold) AssertEquals(goldenPath, actual string)

AssertEquals compares a string to the contents of the golden file. If Gold was configured with an update flag which is true then the golden file will be created if it does not exist or overwritten with the supplied data if it does.

func (*Gold) AssertEqualsHTML

func (g *Gold) AssertEqualsHTML(goldenPath, actual string)

AssertEqualsHTML compares an HTML string to the golden file. Data is noramlized before comparing so data which is formatted differently but semantically equivalent will not fail.

func (*Gold) AssertEqualsJSON

func (g *Gold) AssertEqualsJSON(goldenPath, actual string)

AssertEqualsJSON compares a JSON string to the golden file. Data is noramlized before comparing so data which is formatted differently but semantically equivalent will not fail.

func (*Gold) AssertEqualsTOML

func (g *Gold) AssertEqualsTOML(goldenPath, actual string)

AssertEqualsTOML compares a TOML string to the golden file. Data is noramlized before comparing so data which is formatted differently but semantically equivalent will not fail.

func (*Gold) AssertEqualsYAML

func (g *Gold) AssertEqualsYAML(goldenPath, actual string)

AssertEqualsYAML compares a YAML string to the golden file. Data is noramlized before comparing so data which is formatted differently but semantically equivalent will not fail.

type Option

type Option func(g *Gold)

Option is the signature for functions that configure Gold.

func WithFS

func WithFS(fs afero.Fs) Option

WithFS sets the internal filesystem used for assertions.

func WithFailAfter

func WithFailAfter() Option

WithFailAfter configures whether to stop test execution upon failure.

func WithFlag

func WithFlag(flag bool) Option

WithFlag sets the formatting option.

func WithPrefix

func WithPrefix(elems ...string) Option

WithPrefix sets the folder prefix for golden files.

type Testing

type Testing interface {
	Cleanup(func())
	Error(args ...any)
	Errorf(format string, args ...any)
	Fail()
	FailNow()
	Failed() bool
	Fatal(args ...any)
	Fatalf(format string, args ...any)
	Helper()
	Log(args ...any)
	Logf(format string, args ...any)
	Name() string
	Setenv(key, value string)
	Skip(args ...any)
	SkipNow()
	Skipf(format string, args ...any)
	Skipped() bool
	TempDir() string
}

Testing is a subset of testing.TB that can be reimplemented.

Jump to

Keyboard shortcuts

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