{"id":19152759,"url":"https://github.com/traefik/mocktail","last_synced_at":"2025-04-13T04:59:05.562Z","repository":{"id":37424803,"uuid":"499936259","full_name":"traefik/mocktail","owner":"traefik","description":"Naive code generator that creates mock implementation using testify.mock","archived":false,"fork":false,"pushed_at":"2025-02-07T09:50:04.000Z","size":148,"stargazers_count":209,"open_issues_count":1,"forks_count":18,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-13T04:59:01.690Z","etag":null,"topics":["go","golang","mock","mock-generator","testify","testify-mocking"],"latest_commit_sha":null,"homepage":"https://traefik.io/blog/mocktail-the-mock-generator-for-strongly-typed-mocks/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/traefik.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":"2022-06-04T21:03:53.000Z","updated_at":"2025-04-09T14:52:00.000Z","dependencies_parsed_at":"2024-06-18T22:36:58.400Z","dependency_job_id":"c44093dc-c654-4b20-8e2d-83eacfb08316","html_url":"https://github.com/traefik/mocktail","commit_stats":{"total_commits":57,"total_committers":9,"mean_commits":6.333333333333333,"dds":"0.19298245614035092","last_synced_commit":"b49c602f4dd3ef525ccb259685472c7d2956e780"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traefik%2Fmocktail","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traefik%2Fmocktail/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traefik%2Fmocktail/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traefik%2Fmocktail/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/traefik","download_url":"https://codeload.github.com/traefik/mocktail/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665759,"owners_count":21142123,"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","mock","mock-generator","testify","testify-mocking"],"created_at":"2024-11-09T08:19:17.714Z","updated_at":"2025-04-13T04:59:05.542Z","avatar_url":"https://github.com/traefik.png","language":"Go","readme":"# Mocktail\n\n\u003cp align=\"center\"\u003e\n    \u003cpicture\u003e\n      \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"./mocktail-dark.png\"\u003e\n      \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"./mocktail.png\"\u003e\n      \u003cimg alt=\"Mocktail logo\" src=\"./mocktail.png\"\u003e\n    \u003c/picture\u003e\n\u003c/p\u003e\n\nNaive code generator that creates mock implementation using `testify.mock`.\n\nUnlike [mockery](https://github.com/vektra/mockery), Mocktail generates typed methods on mocks.\n\nFor an explanation of why we created Mocktail, you can read [this article](https://traefik.io/blog/mocktail-the-mock-generator-for-strongly-typed-mocks/).\n\n## How to use\n\n- Create a file named `mock_test.go` inside the package that you can to create mocks.\n- Add one or multiple comments `// mocktail:MyInterface` inside the file `mock_test.go`.\n\n```go\npackage example\n\n// mocktail:MyInterface\n\n```\n\n## How to Install\n\n### Go Install\n\nYou can install Mocktail by running the following command:\n\n```bash\ngo install github.com/traefik/mocktail@latest\n```\n\n### Pre-build Binaries\n\nYou can use pre-compiled binaries:\n\n* To get the binary just download the latest release for your OS/Arch from [the releases page](https://github.com/traefik/mocktail/releases)\n* Unzip the archive.\n* Add `mocktail` in your `PATH`.\n\n## Notes\n\nIt requires testify \u003e= v1.7.0\n\nMocktail can only generate mock of interfaces inside a module itself (not from stdlib or dependencies)\n\nThe `// mocktail` comments **must** be added to a file named `mock_test.go` only,  \ncomments in other files will not be detected\n\n## Examples\n\n```go\npackage a\n\nimport (\n\t\"context\"\n\t\"time\"\n)\n\ntype Pineapple interface {\n\tJuice(context.Context, string, Water) Water\n}\n\ntype Coconut interface {\n\tOpen(string, int) time.Duration\n}\n\ntype Water struct{}\n```\n\n```go\npackage a\n\nimport (\n\t\"context\"\n\t\"testing\"\n)\n\n// mocktail:Pineapple\n// mocktail:Coconut\n\nfunc TestMock(t *testing.T) {\n\tvar s Pineapple = newPineappleMock(t).\n\t\tOnJuice(\"foo\", Water{}).TypedReturns(Water{}).Once().\n\t\tParent\n\n\ts.Juice(context.Background(), \"\", Water{})\n\n\tvar c Coconut = newCoconutMock(t).\n\t\tOnOpen(\"bar\", 2).Once().\n\t\tParent\n\n\tc.Open(\"a\", 2)\n}\n```\n\n## Exportable Mocks\n\nIf you need to use your mocks in external packages just add flag `-e`:\n\n```shell\nmocktail -e\n```\n\nIn this case, mock will be created in the same package but in the file `mock_gen.go`.\n\n\u003c!--\n\nReplacement pattern:\n```\n([.\\s]On)\\(\"([^\"]+)\",?\n\n$1$2(\n```\n\n--\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraefik%2Fmocktail","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftraefik%2Fmocktail","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraefik%2Fmocktail/lists"}