mirror of
https://github.com/jimeh/go-golden.git
synced 2026-02-18 19:06:39 +00:00
a19d4efc3be46f2777be36e481fbdf558bc6f158
refactor: get closer to "stable"
go-golden
Yet another Go package for working with `*.golden` test files, with a focus on simplicity through it's default behavior.
Golden file names are based on the name of the test function and any subtest names by calling t.Name(). File names are sanitized to ensure they're compatible with Linux, macOS and Windows systems regardless of what crazy characters might be in a subtest's name.
Import
import "github.com/jimeh/go-golden"
Usage
Typical usage should look something like this:
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
Languages
Go
93.1%
Makefile
6.9%