{"id":19146662,"url":"https://github.com/tslamic/golden","last_synced_at":"2026-06-12T10:30:16.451Z","repository":{"id":49768053,"uuid":"226553920","full_name":"tslamic/golden","owner":"tslamic","description":"Excruciatingly simple golden file handling.","archived":false,"fork":false,"pushed_at":"2022-07-28T13:19:05.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-03T16:49:44.070Z","etag":null,"topics":["go","golang","golden","golden-file","golden-tests","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/tslamic.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}},"created_at":"2019-12-07T17:50:05.000Z","updated_at":"2022-07-26T09:57:30.000Z","dependencies_parsed_at":"2022-08-30T15:41:17.165Z","dependency_job_id":null,"html_url":"https://github.com/tslamic/golden","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tslamic%2Fgolden","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tslamic%2Fgolden/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tslamic%2Fgolden/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tslamic%2Fgolden/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tslamic","download_url":"https://codeload.github.com/tslamic/golden/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240229976,"owners_count":19768597,"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":["go","golang","golden","golden-file","golden-tests","testing"],"created_at":"2024-11-09T07:47:39.033Z","updated_at":"2026-06-12T10:30:16.417Z","avatar_url":"https://github.com/tslamic.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CircleCI](https://circleci.com/gh/tslamic/golden.svg?style=svg)](https://circleci.com/gh/tslamic/golden) \n[![Go Report Card](https://goreportcard.com/badge/github.com/tslamic/golden)](https://goreportcard.com/report/github.com/tslamic/golden)\n[![Go Reference](https://pkg.go.dev/badge/github.com/tslamic/golden/v2.svg)](https://pkg.go.dev/github.com/tslamic/golden/v2)\n\n# :large_orange_diamond: Golden\n\nExcruciatingly simple golden file handling. \nIf you're unsure what golden files are, check [this video](https://youtu.be/8hQG7QlcLBk?t=735). \n\n## How to use it?\n\n```  \ngo get github.com/tslamic/golden/v2\n```\n\nIf your files are JSON, XML or plain text, you're good to go:\n\n```go\nfunc TestJSON(t *testing.T) {\n    expected := newGreeter()\n    gf := golden.File(\"testdata/hello.json\")\n    gf.Equals(t, expected)\n}\n\nfunc TestXML(t *testing.T) {\n    expected := newCatalog()\n    gf := golden.File(\"testdata/catalog.xml\")\n    gf.Equals(t, expected)\n}\n\nfunc TestText(t *testing.T) {\n    expected := \"Hello World!\"\n    gf := golden.File(\"testdata/world.txt\")\n    gf.Equals(t, expected)\n}\n```\n\nFor custom marshalling or attributes, you can do the following:\n\n```go\ngf := File(name, func(attrs *Attrs) {\n    attrs.Marshaller = func(v interface{}) ([]byte, error) {\n        b := new(bytes.Buffer)\n        err := gob.NewEncoder(b).Encode(v)\n        return b.Bytes(), err\n    }\n})\n```\n\nand if you want to tweak the underlying `[]byte` slices that will be compared, apply some transformers:\n\n```go\nfunc TestJSONWhitespace(t *testing.T) {\n    expected := newGreeter()\n    gf := File(\"testdata/hello_whitespace.json\").Apply(StripWhitespace)\n    gf.Equals(t, expected)\n}\n```\n\nMake sure to run the tests with the `-update` command line argument to populate the files, \nthen drop the flag for all subsequent tests. \n\n## License\n\nThe MIT License. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftslamic%2Fgolden","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftslamic%2Fgolden","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftslamic%2Fgolden/lists"}