{"id":47783920,"url":"https://github.com/hoenn/mimic","last_synced_at":"2026-04-03T14:04:11.253Z","repository":{"id":231165630,"uuid":"747887704","full_name":"hoenn/mimic","owner":"hoenn","description":"Mimic generates lightweight fake implementations of interfaces to inject as dependencies in tests","archived":false,"fork":false,"pushed_at":"2026-03-26T15:00:25.000Z","size":83,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-27T05:32:20.824Z","etag":null,"topics":["fakes","go","golang","mocks","testing"],"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/hoenn.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-01-24T20:50:20.000Z","updated_at":"2026-03-26T15:02:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"b44e09d7-d82f-4eda-af13-9f61b8ad15d3","html_url":"https://github.com/hoenn/mimic","commit_stats":null,"previous_names":["hoenn/minifake"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/hoenn/mimic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoenn%2Fmimic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoenn%2Fmimic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoenn%2Fmimic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoenn%2Fmimic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoenn","download_url":"https://codeload.github.com/hoenn/mimic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoenn%2Fmimic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31355849,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T08:03:20.796Z","status":"ssl_error","status_checked_at":"2026-04-03T08:00:37.834Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["fakes","go","golang","mocks","testing"],"created_at":"2026-04-03T14:03:47.645Z","updated_at":"2026-04-03T14:04:11.246Z","avatar_url":"https://github.com/hoenn.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `mimic`\n`mimic` is a tool for generating stubbed implementations, or fakes, of interfaces to inject as dependencies during tests that are as light as possible. Other tools like `mockgen` and `counterfeiter` bring in a ton of functionality that is excessive for some projects and make much larger generated fakes. `mimic` generates the bare minimum.\n\nWith this simplistic implementation you can recreate missing features like call counts, thread safety, returns for call, etc., in each stub as needed.\n\n### Usage\nUse with a `go:generate` directive:\n```go\npackage foo\n\n//go:generate go run github.com/hoenn/mimic InterfaceA,InterfaceB\ntype InterfaceA interface {}\n// ...\ntype InterfaceB interface {}\n```\n\nYou can also specify the file the interface appears in in the generate directive, which can be useful if you want a single `generate.go` file.\n```go\npackage foo\n// Generates fileA_fake.go and fileB_fake.go\n//go:generate go run github.com/hoenn/mimic ./fileA.go InterfaceA,InterfaceB\n//go:generate go run github.com/hoenn/mimic ./fileB.go InterfaceC\n```\n\n## Functionality Matrix\n| Feature | Status | Notes |\n|---|---|---|\n| Basic methods | Yes | Named params, results, zero values |\n| Unnamed params | Yes | Auto-named `arg0`, `arg1`, ... |\n| Variadic params | Yes | Forwarded with `...` |\n| Empty interfaces | Yes | Generates empty struct |\n| All builtin types | Yes | Correct zero values |\n| Pointer/slice/map/chan/func returns | Yes | Returns `nil` |\n| Array returns | Yes | Returns `[N]T{}` |\n| `interface{}`/`any` returns | Yes | Returns `nil` |\n| Named struct returns | Yes | Returns `T{}` |\n| `pkg.Type` returns | Yes | Returns `pkg.T{}` |\n| Multiple interfaces per file | Yes | Comma-separated names |\n| Same-file embedded interfaces | Yes | Recursive resolution |\n| Transitive embeds (A→B→C) | Yes | Recursive |\n| Mixed embeds + methods | Yes | Both collected |\n| Cross-package interface and parameter embeds (`io.Reader`) | Yes | Handled |\n| Compile time interface assertions | Yes* | Leaves a comment instead for unsupported complex type constraints |\n| Generic interfaces (`T[K]`) | Yes | Type params + constraints preserved |\n| Diamond embedding dedup | No | Will generate duplicate fields |\n| Overlapping method dedup (Go 1.14+) | No | Same issue |\n| Type constraint unions (`~int \\| string`) | No | Not handled |\n\n### Same-package generation\n`mimic` generates fakes into the same package as the interface definition. This is a deliberate design choice as same-package generation has full visibility into unexported types and avoids circular dependencies. Interfaces with unexported types in their method signatures work without any additional configuration. For example:\n``` go\ntype message string\ntype Client interface {\n    Send(msg *message) error // unexported type\n}\n```\n\nOther tools that generate fakes into separate packages cannot compile fakes for an interface like this, as the unexported type will be unavailable in the `fakefoo` package.\n\nThe tradeoff for this functionality is that generated fakes are compiled with production code. In practice this should have minimal impact since the generated fake is a lightweight struct.\n\n\n### Examples\n```go\n// testdata.go where an interface is defined.\npackage testdata\n\ntype Job struct {\n\tname string\n}\ntype JobQueuer interface {\n\tEnqueue(j *Job) error\n\tDequeue(j *Job) error\n\tQueue() []*Job\n}\n\n\n// testdata_fake.go where the fake is generated.\n// Code generated by mimic; DO NOT EDIT.\npackage testdata\n\n// FakeJobQueuer implements JobQueuer.\ntype FakeJobQueuer struct {\n\tEnqueueStub func(j *Job) error\n\tDequeueStub func(j *Job) error\n\tQueueStub   func() []*Job\n}\n\nvar _ JobQueuer = (*FakeJobQueuer)(nil)\n\nfunc (fakeImpl *FakeJobQueuer) Enqueue(j *Job) error {\n\tif fakeImpl.EnqueueStub != nil {\n\t\treturn fakeImpl.EnqueueStub(j)\n\t}\n\treturn nil\n}\nfunc (fakeImpl *FakeJobQueuer) Dequeue(j *Job) error {\n\tif fakeImpl.DequeueStub != nil {\n\t\treturn fakeImpl.DequeueStub(j)\n\t}\n\treturn nil\n}\nfunc (fakeImpl *FakeJobQueuer) Queue() []*Job {\n\tif fakeImpl.QueueStub != nil {\n\t\treturn fakeImpl.QueueStub()\n\t}\n\treturn nil\n}\n\n\n// testdata_test.go where we inject our fake for testing and\n// define the functions to assert behaviors of the dependent.\nfunc TestJobQueuer(t *testing.T) {\n\tf := \u0026FakeJobQueuer{\n\t\tEnqueueStub: func(j *Job) error {\n\t\t\t// Implement behavior you want to fake, like returning\n\t\t\t// a specific error.\n\t\t},\n\t\tDequeueStub: func(j *Job) error {\n\t\t\t// Or use a bool to check if a function is ever called.\n\t\t\t// dequeueCalled = true\n\t\t\t// dequeueCalls++\n\t\t},\n\t\t// Undefined QueueStub() returns zero value when called.\n\t}\n\tsvc := newComplicatedService(f)\n\t// Expected dequeueCalled to be true\n\t// Expected some error to happen when queueing\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoenn%2Fmimic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoenn%2Fmimic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoenn%2Fmimic/lists"}