{"id":19135920,"url":"https://github.com/sonalys/fake","last_synced_at":"2025-05-06T20:07:00.078Z","repository":{"id":225005947,"uuid":"764814947","full_name":"sonalys/fake","owner":"sonalys","description":"A type-safe approach for Golang mock generation.","archived":false,"fork":false,"pushed_at":"2024-06-10T07:25:01.000Z","size":75,"stargazers_count":19,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-26T15:59:59.638Z","etag":null,"topics":["codegen","codegenerator","go","golang","mock","mocking"],"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/sonalys.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":"2024-02-28T19:01:00.000Z","updated_at":"2025-04-05T17:32:07.000Z","dependencies_parsed_at":"2024-11-09T06:33:21.305Z","dependency_job_id":"095b3221-d5c1-41f8-9b15-b932d3b99bda","html_url":"https://github.com/sonalys/fake","commit_stats":null,"previous_names":["sonalys/fake"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonalys%2Ffake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonalys%2Ffake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonalys%2Ffake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonalys%2Ffake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sonalys","download_url":"https://codeload.github.com/sonalys/fake/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252761144,"owners_count":21800124,"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":["codegen","codegenerator","go","golang","mock","mocking"],"created_at":"2024-11-09T06:32:39.156Z","updated_at":"2025-05-06T20:07:00.009Z","avatar_url":"https://github.com/sonalys.png","language":"Go","readme":"# Fake\n\nFake is a Go type-safe [mocking](https://en.wikipedia.org/wiki/Mock_object) generator. It automatically creates type-safe mocks for any public interface.\n\n## Features\n\n- Type-safe mock generation\n- Support for generics\n- Granular mock generation\n- Mock cache for ultra-fast mock regeneration\n- Function call configuration, with Repeatability and Optional calls\n- Automatic call assertion\n- Caching, only regenerate updated interfaces\n- Automatic cleanup of generated mocks from removed code\n\n## Installation\n\n### Go install\n\nMake sure `$GO_PATH/bin` is in your `$PATH`\n\n`go install github.com/sonalys/fake/entrypoint/fake@latest`\n\n### Release download\n\nVisit the [Release Page](https://github.com/sonalys/fake/releases) and download the correct binary for your architecture/os.\n\n### Docker\n\nYou can safely run fake from a docker container using\n\n`docker run --rm -u $(id -u):$(id -g) -v .:/code ghcr.io/sonalys/fake:latest /fake -input /code -output /code/mocks`\n\n## Usage\n\n```\n\nUsage:\n\n  fake -input PATH -output mocks -ignore tests\n\nThe flags are:\n\n  FLAG          TYPE      DEFAULT   DESCRIPTION\n  -input        []STRING  .         Folder to scan for interfaces, can be invoked multiple times\n  -output       STRING    mocks     Output folder, it will follow a tree structure repeating the package path\n  -ignore       []STRING            Folder to ignore, can be invoked multiple times\n  -interface    []STRING            Usually used with go:generate for granular mock generation for specific interfaces\n  -mockPackage  STRING    mocks     Used with -interface. Specify the package name of the generated mock\n\n```\n\n## Examples\n\nA very simple example would be:\n\n```go\ntype UserDB interface {\n\tLogin(userID string) error\n}\n```\n\nWill generate the following mock:\n\n```go\ntype UserDB interface {\n\tLogin(userID string) error\n}\ntype StubInterface struct {\n\tsetupLogin      mockSetup.Mock[func(userID string) error]\n}\n\nfunc (s *StubInterface[T]) OnLogin(funcs ...func(userID string) error) Config\nfunc (s *StubInterface[T]) Login(userID string) error\n...\n```\n\nGranular generation with go generate:\n\n```go\n//go:generate fake -interface Reader\ntype Reader interface {\n\tio.Reader\n}\n// or\n//go:generate go run github.com/sonalys/fake/entrypoint/fake -interface Reader\ntype Reader interface {\n\tio.Reader\n}\n```\n\n---\n\n## Example usage for tests\n\n```go\n\nfunc Test_Stub(t *testing.T) {\n  mock := mocks.NewUserDB(t) // Setup call expectations\n  config := mock.OnLogin(func(userID string) error {\n    require.NotEmpty(t, userID)\n    return nil\n  })\n  // Here you can configure it with:\n  config.Repeat(1) // Repeat 1 is default behavior.\n  // or with .Maybe(), which won't fail tests it not called.\n  config.Maybe()\n\n  var userDB UserDB = mock\n  userDB.Login(\"userID\") // Will call the previous function.\n}\n```\n\n---\n\n## Contributors\n\nAny issues or improvements discussions are welcome! Feel free to contribute.\nThank you for your collaboration!\n\n\u003ca href=\"https://github.com/sonalys/fake/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=sonalys/fake\" /\u003e\n\u003c/a\u003e\n\n---\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonalys%2Ffake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonalys%2Ffake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonalys%2Ffake/lists"}