{"id":13645863,"url":"https://github.com/sebdah/goldie","last_synced_at":"2025-04-04T06:08:50.392Z","repository":{"id":41371448,"uuid":"77579241","full_name":"sebdah/goldie","owner":"sebdah","description":"Golden file testing for Go","archived":false,"fork":false,"pushed_at":"2024-08-04T12:09:56.000Z","size":187,"stargazers_count":241,"open_issues_count":6,"forks_count":20,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T05:13:12.053Z","etag":null,"topics":["fixtures","golang","golden","golden-test","testing"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sebdah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-29T03:22:15.000Z","updated_at":"2025-03-27T08:18:16.000Z","dependencies_parsed_at":"2024-08-04T14:15:12.391Z","dependency_job_id":null,"html_url":"https://github.com/sebdah/goldie","commit_stats":{"total_commits":80,"total_committers":16,"mean_commits":5.0,"dds":0.4,"last_synced_commit":"eb2b20ed12af21343d53b82fd1b6b367e9ae4292"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebdah%2Fgoldie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebdah%2Fgoldie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebdah%2Fgoldie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebdah%2Fgoldie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebdah","download_url":"https://codeload.github.com/sebdah/goldie/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247128751,"owners_count":20888235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fixtures","golang","golden","golden-test","testing"],"created_at":"2024-08-02T01:02:43.789Z","updated_at":"2025-04-04T06:08:50.365Z","avatar_url":"https://github.com/sebdah.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# goldie - Golden test utility for Go\n\n[![GoDoc](https://godoc.org/github.com/sebdah/goldie?status.svg)](https://godoc.org/github.com/sebdah/goldie)\n![Go](https://github.com/sebdah/goldie/workflows/Go/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/sebdah/goldie)](https://goreportcard.com/report/github.com/sebdah/goldie)\n\n`goldie` is a golden file test utility for Go projects. It's typically used for\ntesting responses with larger data bodies.\n\nThe concept is straight forward. Valid response data is stored in a \"golden\nfile\". The actual response data will be byte compared with the golden file and\nthe test will fail if there is a difference.\n\nUpdating the golden file can be done by running `go test -update ./...`.\n\nSee the [GoDoc](https://godoc.org/github.com/sebdah/goldie) for API reference\nand configuration options.\n\n# Installation\n\nInstall the latest version, v2, with:\n\n```shell\ngo get -u github.com/sebdah/goldie/v2\n```\n\nFor the older v1 release, please use:\n\n```shell\ngo get -u github.com/sebdah/goldie\n```\n\n# Example usage\n\n## Basic assertions\n\nThe below example fetches data from a REST API. The last line in the test is the\nactual usage of `goldie`. It takes the HTTP response body and asserts that it's\nwhat is present in the golden test file.\n\n```\nfunc TestExample(t *testing.T) {\n    recorder := httptest.NewRecorder()\n\n    req, err := http.NewRequest(\"GET\", \"/example\", nil)\n    assert.Nil(t, err)\n\n    handler := http.HandlerFunc(ExampleHandler)\n    handler.ServeHTTP()\n\n    g := goldie.New(t)\n    g.Assert(t, \"example\", recorder.Body.Bytes())\n}\n```\n\n## Assertions using templates\n\nIf some values in the golden file can change depending on the test, you can use\ngolang template in the golden file and pass the data to `AssertWithTemplate`.\n\n### example.golden\n```\nThis is a {{ .Type }} file.\n```\n\n### Test\n```\nfunc TestTemplateExample(t *testing.T) {\n    recorder := httptest.NewRecorder()\n\n    req, err := http.NewRequest(\"POST\", \"/example/Golden\", nil)\n    assert.Nil(t, err)\n\n    handler := http.HandlerFunc(ExampleHandler)\n    handler.ServeHTTP()\n\n    data := struct {\n        Type\tstring\n    }{\n        Type:\t\"Golden\",\n    }\n\n    g := goldie.New(t)\n    g.AssertWithTemplate(t, \"example\", data, recorder.Body.Bytes())\n}\n```\n\nThen run your test with the `-update` flag the first time to store the result.\n\n`go test -update ./...`\n\nFor any consecutive runs where you actually want to compare the data, simply\ndrop the `-update` flag.\n\n`go test ./...`\n\n## Validating JSON and XML output\n\nIf you are asserting JSON and XML data, you can use the handy `AssertJson` and\n`AssertXml` functions that will nicely indent the golden validation files for\nbetter readability.\n\n# Flags\n\n## Clean output directory\n\nUsing `-update` along with `-clean` flag will clear the fixture directory before updating golden files.\n\n`go test -update -clean ./...`\n\n\n# Options\n\n`goldie` supports a number of configuration options that will alter the behavior\nof the library.  These options should be passed into the `goldie.New()` method.\n\n```\nfunc TestNewExample(t *testing.T) {\n    g := goldie.New(\n        t,\n        goldie.WithFixtureDir(\"test-fixtures\"),\n        goldie.WithNameSuffix(\".golden.json\"),\n        goldie.WithDiffEngine(goldie.ColoredDiff),\n        goldie.WithTestNameForDir(true),\n    )\n\n    g.Assert(t, \"example\", []byte(\"my example data\"))\n}\n```\n\n## Available options\n\n| Option                     | Comment                                                  | Default\n|----------------------------|----------------------------------------------------------|-------------\n| `WithFixtureDir`           | Set fixture dir name                                     | `testdata`\n| `WithNameSuffix`           | Suffix for fixture files.                                | `.golden`\n| `WithDirPerms`             | Directory permissions for fixtures                       | `0755`\n| `WithFilePerms`            | File permissions for fixtures                            | `0644`\n| `WithDiffEngine`           | Diff engine to use for diff output                       | `ClassicDiff`\n| `WithDiffFn`               | Custom diff logic to be used                             | None\n| `WithIgnoreTemplateErrors` | Ignore errors from templates                             | `false`\n| `WithTestNameForDir`       | Create a folder with the tests name for the fixtures     | `false`\n| `WithSubTestNameForDir`    | Create a folder with the sub tests name for the fixtures | `false`\n\n## Diff output\n\nGoldie has three output modes; classic diff (default), colored diffs and simple\nmode.\n\nYou can select your preferred output using the `WithDiffEngine` option:\n\n```\ng.New(\n    t,\n    goldie.WithDiffEngine(goldie.ColoredDiff), // Simple, ColoredDiff, ClassicDiff\n)\n```\n\n# Goldie v2\n\nWith the release of Goldie v2.0.0 we are introducing features that will break\nbackwards compatibility with older versions of the test helper. A few things\nhave changed:\n\n## New default fixture directory\n\nThere is a new default directory for fixtures, `testdata`. This directory is a\nbetter default as it is more widely used in the Go community (including the\nstandard library). See issue [#10](https://github.com/sebdah/goldie/issues/10)\nfor details.\n\n## New way to initialize Goldie\n\nWith the introduction of the functional options we also introduced `goldie.New`,\nwhich is initializing Goldie. `Assert*` and other methods are now accessed like:\n\n```\ng := goldie.New(t)\ng.Assert(t, ...)\n```\n\n# FAQ\n\n## Do you need any help in the project?\n\nYes, please! Pull requests are most welcome. On the wish list:\n\n- Unit tests.\n\n## Why the name `goldie`?\n\nThe name comes from the fact that it's for Go and handles golden file testing.\nBut yes, it may not be the best name in the world.\n\n### How did you come up with the idea?\n\nThis is based on the great [Advanced Go\ntesting](https://www.youtube.com/watch?v=yszygk1cpEc) talk by\n[@mitchellh](https://twitter.com/mitchellh).\n\n# License\n\nMIT\n\nCopyright 2016 Sebastian Dahlgren \u003csebastian.dahlgren@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebdah%2Fgoldie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebdah%2Fgoldie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebdah%2Fgoldie/lists"}