Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Golden file testing for Go
| Date | Stars |
|---|---|
| 2026-07-24 | 265 |
| 2026-07-25 | 265 |
| 2026-07-28 | 265 |
| 2026-07-30 | 265 |
| 2026-08-06 | 265 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
# goldie - Golden test utility for Go
[](https://godoc.org/github.com/sebdah/goldie)

[](https://goreportcard.com/report/github.com/sebdah/goldie)
`goldie` is a golden file test utility for Go projects. It's typically used for
testing responses with larger data bodies.
The concept is straight forward. Valid response data is stored in a "golden
file". The actual response data will be byte compared with the golden file and
the test will fail if there is a difference.
Updating the golden file can be done by running `go test -update ./...`.
See the [GoDoc](https://godoc.org/github.com/sebdah/goldie) for API reference
and configuration options.
# Installation
Install the latest version, v2, with:
```shell
go get -u github.com/sebdah/goldie/v2
```
For the older v1 release, please use:
```shell
go get -u github.com/sebdah/goldie
```
# Example usage
## Basic assertions
The below example fetches data from a REST API. The last line in the test is the
actual usage of `goldie`. It takes the HTTP response body and asserts that it's
what is present in the golden test file.
```
func TestExample(t *testing.T) {
recorder := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/example", nil)
assert.Nil(t, err)
handler := http.HandlerFunc(ExampleHandler)
handler.ServeHTTP()
g := goldie.New(t)
g.Assert(t, "example", recorder.Body.Bytes())
}
```
## Assertions using templates
If some values in the golden file can change depending on the test, you can use
golang template in the golden file and pass the data to `AssertWithTemplate`.
### example.golden
```
This is a {{ .Type }} file.
```
### Test
```
func TestTemplateExample(t *testing.T) {
recorder := httptest.NewRecorder()
req, err := http.NewRequest("POST", "/example/Golden", nil)
assert.Nil(t, err)
handler := http.HandlerFunc(ExampleHandler)
handler.ServeHTTP()
data := struct {
Type string
}{
Type: "Golden",
}
g := goldie.New(t)
g.AssertWithTemplate(t, "example", data, recorder.Body.Bytes())
}
```
Then run your test with the `-update` flag the first time to store the result.
`go test -update ./...`
For any consecutive runs where you actually want to compare the data, simply
drop the `-update` flag.
`go test ./...`
## Validating JSON and XML output
If you are asserting JSON and XML data, you can use the handy `AssertJson` and
`AssertXml` functions that will nicely indent the golden validation files for
better readability.
# Flags
## Clean output directory
Using `-update` along with `-clean` flag will clear the fixture directory before updating golden files.
`go test -update -clean ./...`
# Options
`goldie` supports a number of configuration options that will alter the behavior
of the library. These options should be passed into the `goldie.New()` method.
```
func TestNewExample(t *testing.T) {
g := goldie.New(
t,
goldie.WithFixtureDir("test-fixtures"),
goldie.WithNameSuffix(".golden.json"),
goldie.WithDiffEngine(goldie.ColoredDiff),
goldie.WithTestNameForDir(true),
)
g.Assert(t, "example", []byte("my example data"))
}
```
## Available options
| Option | Comment | Default
|----------------------------|----------------------------------------------------------|-------------
| `WithFixtureDir` | Set fixture dir name | `testdata`
| `WithNameSuffix` | Suffix for fixture files. | `.golden`
| `WithDirPerms` | Directory permissions for fixtures | `0755`
| `WithFilePerms` | File permissions for fixtures | Excerpt of 7,069 characters
Read on GitHubWould you bet a product on this? Bounded 0–100 and slow moving.
matched fp:f2c147f5426f2f40, topic:testing