Jim Myhrberg 550ba17fb0 feat(options): add optional Options arguments to New() function (#14)
Enables simpler creation of custom *Golden instances, as you can just pass in the custom values to New(), rather than modifying fields after increating the Golden instance.
2025-04-05 12:28:57 +01:00
2025-03-24 13:19:39 +00:00
2025-03-24 13:19:39 +00: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)

    want := golden.Do(t, got)

    assert.Equal(t, want, got)
}

The above example will read/write to:

  • testdata/TestExampleMyStruct.golden

The call to golden.Do() is equivalent to:

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

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 283 KiB
Languages
Go 93.1%
Makefile 6.9%