{"id":37203096,"url":"https://github.com/leorolland/matchergen","last_synced_at":"2026-01-14T23:25:34.179Z","repository":{"id":204160075,"uuid":"711225134","full_name":"leorolland/matchergen","owner":"leorolland","description":"Generate gomock matchers from your models","archived":true,"fork":false,"pushed_at":"2023-11-06T19:49:22.000Z","size":8,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-19T16:40:34.189Z","etag":null,"topics":["generator","go","gomock","matcher","testing","tool"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leorolland.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-28T15:32:24.000Z","updated_at":"2023-11-06T19:49:48.000Z","dependencies_parsed_at":"2023-11-07T02:42:26.922Z","dependency_job_id":"a3527819-4b0e-4f45-8362-8defa2a778a7","html_url":"https://github.com/leorolland/matchergen","commit_stats":null,"previous_names":["leorolland/matchergen"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/leorolland/matchergen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leorolland%2Fmatchergen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leorolland%2Fmatchergen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leorolland%2Fmatchergen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leorolland%2Fmatchergen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leorolland","download_url":"https://codeload.github.com/leorolland/matchergen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leorolland%2Fmatchergen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28438011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T22:37:52.437Z","status":"ssl_error","status_checked_at":"2026-01-14T22:37:31.496Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["generator","go","gomock","matcher","testing","tool"],"created_at":"2026-01-14T23:25:33.523Z","updated_at":"2026-01-14T23:25:34.168Z","avatar_url":"https://github.com/leorolland.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gomock matcher generator\n\nProject has been continued [here](https://github.com/Joffref/genz)\n\nGenerate [gomock matcher](https://pkg.go.dev/github.com/golang/mock/gomock#Matcher) implementations from your models.\n\n```shell\ngo install github.com/leorolland/matchergen\n```\n\n## How it works\n1. Run `matchergen -Type Human ./mypackage`\n2. Generator searches for all accessor methods of type `Human`, they will be used for the match assertion.\n4. Generator creates a `HumanMatcher` which implements [gomock Matcher](https://pkg.go.dev/github.com/golang/mock/gomock#Matcher) that can be instanciated with `NewHumanMatcher(expectedName, expectedAge)`. The matcher can be passed to gomocks `.EXPECT()` methods that expect a `Human` as a parameter.\n5. gomock calls `Matches` on the generated matcher, which validates that all the accessors return the expected value (which are passed in `NewHumanMatcher`)\n\n## Usage\n\n1. Add `//go:generate matchergen` to your model:\n(try in `/examples` directory)\n```go\npackage model\n\n//go:generate matchergen -type Human -output ../modeltest/human_matcher.go .\ntype Human struct {\n\tname string\n\tage  int\n}\n\nfunc NewHuman(name string, age int) *Human {\n\treturn \u0026Human{name, age}\n}\n\nfunc (h *Human) Name() string {\n\treturn h.name\n}\n\nfunc (h *Human) Age() int {\n\treturn h.age\n}\n```\n\n2. Run `go generate ./examples/model`\n\n3. Use generated modeltest\nGenerated file:\n```go\ntype HumanMatcher struct {\n\tcomparator *comparator\n\n\tname string\n\tage  int\n}\n\nfunc NewHumanMatcher(name string, age int) *HumanMatcher {\n\treturn \u0026HumanMatcher{\n\t\tname: name,\n\t\tage:  age,\n\t}\n}\n\nfunc (h *HumanMatcher) Matches(arg interface{}) bool {\n\th.comparator = \u0026comparator{}\n\n\thuman, ok := arg.(*model.Human)\n\tif !ok {\n\t\th.comparator.equal(\"type\", \"*model.Human\", fmt.Sprintf(\"%T\", arg))\n\t\treturn h.comparator.matches()\n\t}\n\n\th.comparator.equal(\"name\", h.name, human.Name())\n\th.comparator.equal(\"age\", h.age, human.Age())\n\n\treturn h.comparator.matches()\n}\n\nfunc (h *HumanMatcher) Got(got interface{}) string {\n\treturn getDiff(h.comparator.got)\n}\n\nfunc (h *HumanMatcher) String() string {\n\treturn getValue(h.comparator.wanted)\n}\n```\n\nUsge in tests\n```go\nhumanServiceMock = NewHumanServiceMock(gomock.NewController())\n...\nhumanServiceMock.EXPECT().CreateHuman(NewHumanMatcher(\"joe\", 30)).Return(nil)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleorolland%2Fmatchergen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleorolland%2Fmatchergen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleorolland%2Fmatchergen/lists"}