{"id":18937412,"url":"https://github.com/verifytests/verify.go","last_synced_at":"2025-04-15T18:32:00.090Z","repository":{"id":40413251,"uuid":"466436520","full_name":"VerifyTests/Verify.Go","owner":"VerifyTests","description":"Verify.Go is a snapshot tool for Go language that simplifies the assertion of complex data models and documents.","archived":false,"fork":false,"pushed_at":"2024-03-02T14:57:27.000Z","size":1160,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-29T01:02:14.896Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/VerifyTests.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","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":"2022-03-05T11:41:59.000Z","updated_at":"2025-02-11T09:45:09.000Z","dependencies_parsed_at":"2024-06-20T18:55:58.530Z","dependency_job_id":null,"html_url":"https://github.com/VerifyTests/Verify.Go","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VerifyTests","download_url":"https://codeload.github.com/VerifyTests/Verify.Go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249129224,"owners_count":21217307,"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":[],"created_at":"2024-11-08T12:11:04.066Z","updated_at":"2025-04-15T18:31:55.078Z","avatar_url":"https://github.com/VerifyTests.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003cimg src='./icon.png' height='30px'\u003e Verify.Go\n\n[![Discussions](https://img.shields.io/badge/Verify-Discussions-yellow?svg=true\u0026style=flat-square\u0026label=)](https://github.com/VerifyTests/Discussions/discussions) [![Build](https://github.com/VerifyTests/Verify.Go/actions/workflows/build.yml/badge.svg)](https://github.com/VerifyTests/Verify.Go/actions/workflows/build.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/VerifyTests/Verify.Go?style=flat-square)](https://goreportcard.com/report/github.com/VerifyTests/Verify.Go) [![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?style=flat-square\u0026logo=go\u0026logoColor=white)](https://pkg.go.dev/github.com/VerifyTests/Verify.Go)\n\n\u003c!--\n[![GitHub release](https://img.shields.io/github/release/VerifyTests/Verify.Go.svg?style=flat-square)](https://github.com/VerifyTests/Verify.Go/releases/latest)\n--\u003e\n\nVerify.Go is a snapshot tool for Go language that simplifies the assertion of complex data models and documents.\n\nVerify is called on the test result during the assertion phase. It serializes that result and stores it in a file that matches the test name. On the next test execution, the result is again serialized and compared to the existing file. The test will fail if the two snapshots do not match: either the change is unexpected, or the reference snapshot needs to be updated to the new result.\n\n## Installation\n\nTo install, add the library directly to your Go project.\n\n```cmd\ngo get github.com/VerifyTests/Verify.Go\n```\n\n## Snapshot management\n\nAccepting or declining a snapshot file is part of the core workflow of Verify. There are several ways to do this and the approach(s) selected is a personal preference.\n\n * In the Windows Tray via [DiffEngineTray](https://github.com/VerifyTests/DiffEngine/blob/main/docs/tray.md)\n * Manually making the change in the launched diff tool. Either with a copy paste, or some tools have commands to automate this via a shortcut or a button.\n * Manually on the file system, by renaming the `.received.` file to `.verified.`. This can be automated via a scripted to bulk accept all (by matching a pattern) `.received.` files.\n\n ## Usage\n\n ### Struct being tested\n\nGiven a struct to be tested:\n\n```go\nvar person = Person{\n    ID:         uuid.MustParse(\"ebced679-45d3-4653-8791-3d969c4a986c\"),\n    Title:      Mr,\n    FamilyName: \"Smith\",\n    GivenNames: \"John\",\n    Dob:        time.Date(2022, 02, 01, 1, 2, 3, 4, time.Local),\n    Spouse:     \"Jill\",\n    Address: Address{\n        Street:  \"4 Puddle Lane\",\n        Country: \"USA\",\n    },\n    Children: []string{\"Sam\", \"Mary\"},\n}\n```\n\n### Go Tests\n\nTests are created using standard Go test functions. A test file named `verify_api_test.go` can have following Test function:\n\n```go\nimport (\n    \"github.com/VerifyTests/Verify.Go/verifier\"\n)\n\nfunc TestVerifyingStructs(t *testing.T) {\n    verifier.Verify(t, person)\n}\n```\n\n### Initial Verification\n\nWhen the test is initially run will fail. If a diff tool is detected it will display the diff.\n\n![InitialDiff](./docs/InitialDiff.png)\n\nTo verify the result:\n\n * Use the diff tool to accept the changes, or\n * Manually copy the text to the new file\n\n### Verified result\n\nThis will result in the `TestFile.TestVerifyingStructs.verified.txt` being created:\n\n```txt\n{\n    \"given_names\": \"John\",\n    \"family_name\": \"Smith\",\n    \"spouse\": \"Jill\",\n    \"address\": {\n        \"street\": \"4 Puddle Lane\",\n        \"country\": \"USA\"\n    },\n    \"children\": [\n        \"Sam\",\n        \"Mary\"\n    ],\n    \"title\": \"Mr.\",\n    \"id\": \"Guid_1\",\n    \"dob\": \"Time_1\"\n}\n```\n\n### Subsequent Verification\n\nIf the implementation of the struct changes:\n\n```go\nvar person = Person{\n    ID:         uuid.MustParse(\"ebced679-45d3-4653-8791-3d969c4a986c\"),\n    Title:      Mr,\n    FamilyName: \"Smith\",\n    GivenNames: \"John James\",\n    Dob:        time.Date(2022, 02, 01, 1, 2, 3, 4, time.Local),\n    Spouse:     \"Jill\",\n    Address: Address{\n        Street:  \"64 Barnett Street\",\n        Country: \"USA\",\n    },\n    Children: []string{\"Sam\", \"Mary\"},\n}\n```\n\nAnd the test is re-run, it will fail.\n\nThe Diff Tool will display the diff:\n\n![SecondDiff](./docs/SecondDiff.png)\n\nThe same approach can be used to verify the results where the change to `*.verified.*` is committed to source control along with the change to the struct.\n\n## Received and Verified\n\n * **All `*.verified.*` files should be committed to source control.**\n * **All `*.received.*` files should be excluded from source control.**\n\n## Configuring Verify\n\nSettings can be configured by calling the `Configure` method on the `Verifier` interface. Default setting will be used, unless otherwise specified.\n\n```go\nverifier.NewVerifier(t,\n   verifier.AddScrubber(func(str string) string {\n       return strings.ReplaceAll(str, \"String to verify\", \"new value\")\n   }),\n).Verify(\"String to verify\")\n```\n\n## Versioning\n\nVerify follows [Semantic Versioning](https://semver.org/). Small changes in the resulting snapshot files may be deployed in a minor version. As such updates to `Verify.Go` should be done as follows:\n\n * Updates `Verify.Go` packages in isolation\n * Re-run all tests.\n * If there are changes, ensure they look correct given the release notes. If the changes do not look correct, raise an issue.\n * Accept those changes.\n\nSnapshot changes do not trigger a major version change to avoid causing [Diamond dependency](https://en.wikipedia.org/wiki/Dependency_hell#Problems) issues for downstream extensions.\n\n\n## More Documentation\n\n- This is a work in progress...\n\n## Icon\n\n[Go](https://thenounproject.com/term/go/4114128/) designed by [Jonata Hangga](https://thenounproject.com/stan82ly/) from [The Noun Project](https://thenounproject.com).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fverifytests%2Fverify.go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fverifytests%2Fverify.go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fverifytests%2Fverify.go/lists"}