mirror of
https://github.com/jimeh/go-golden.git
synced 2025-12-21 21:36:40 +00:00
No description
|
|
||
|---|---|---|
| .github | ||
| testdata | ||
| .gitignore | ||
| .golangci.yml | ||
| CHANGELOG.md | ||
| example_test.go | ||
| go.mod | ||
| go.sum | ||
| golden.go | ||
| golden_test.go | ||
| LICENSE | ||
| Makefile | ||
| options.go | ||
| options_test.go | ||
| README.md | ||
| sanitize.go | ||
| sanitize_test.go | ||
| testing_t.go | ||
| update.go | ||
| update_test.go | ||
go-golden
Yet another Go package for working with *.golden test files,
with a focus on simplicity.
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.