Jim Myhrberg 4e07a1a657 wip(assertion): incomplete refactor of tests and assertion helpers
Tests have started using github.com/jimeh/go-mocktesting which allows
testing unhappy paths where t.Fatal() and related functions are called.
2021-12-28 02:24:00 +00:00
2021-10-28 02:25:16 +01:00
2021-09-16 02:46:51 +01:00

go-golden

Yet another Go package for working with *.golden test files, with a focus on simplicity.

Go Reference Actions Status Coverage GitHub issues GitHub pull requests License Status

Import

import "github.com/jimeh/go-golden"

Usage

func TestExampleMyStruct(t *testing.T) {
	got, err := json.Marshal(&MyStruct{Foo: "Bar"})
	require.NoError(t, err)

	if golden.Update() {
		golden.Set(t, got)
	}
	want := golden.Get(t)

	assert.Equal(t, want, got)
}

The above example will read/write to:

  • testdata/TestExampleMyStruct.golden

To update the golden file (have golden.Update() return true), simply set the GOLDEN_UPDATE environment variable to one of 1, y, t, yes, on, or true when running tests.

Documentation

Please see the Go Reference for documentation and examples.

License

MIT

Description
Yet another Go package for working with *.golden test files, with a focus on simplicity.
Readme MIT 284 KiB
Languages
Go 93.1%
Makefile 6.9%