https://github.com/jimeh/go-golden
Yet another Go package for working with *.golden test files, with a focus on simplicity.
https://github.com/jimeh/go-golden
go go-golden go-test go-test-helper go-testing golang golden-file
Last synced: over 1 year ago
JSON representation
Yet another Go package for working with *.golden test files, with a focus on simplicity.
- Host: GitHub
- URL: https://github.com/jimeh/go-golden
- Owner: jimeh
- License: mit
- Created: 2021-09-16T01:33:17.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-22T02:00:28.000Z (over 1 year ago)
- Last Synced: 2025-03-22T03:18:01.540Z (over 1 year ago)
- Topics: go, go-golden, go-test, go-test-helper, go-testing, golang, golden-file
- Language: Go
- Homepage: https://pkg.go.dev/github.com/jimeh/go-golden
- Size: 105 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
go-golden
Yet another Go package for working with *.golden test files,
with a focus on simplicity.
## Import
```go
import "github.com/jimeh/go-golden"
```
## Usage
```go
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:
```go
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](https://pkg.go.dev/github.com/jimeh/go-golden#section-documentation)
for documentation and examples.
## License
[MIT](https://github.com/jimeh/go-golden/blob/master/LICENSE)