{"id":13413927,"url":"https://github.com/matryer/moq","last_synced_at":"2026-04-01T19:32:53.884Z","repository":{"id":37709790,"uuid":"66832342","full_name":"matryer/moq","owner":"matryer","description":"Interface mocking tool for go generate","archived":false,"fork":false,"pushed_at":"2026-03-20T06:24:39.000Z","size":2521,"stargazers_count":2190,"open_issues_count":29,"forks_count":134,"subscribers_count":14,"default_branch":"main","last_synced_at":"2026-03-20T22:59:40.759Z","etag":null,"topics":["codegen","golang","mocking","testing"],"latest_commit_sha":null,"homepage":"http://bit.ly/meetmoq","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/matryer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"matryer"}},"created_at":"2016-08-29T10:00:17.000Z","updated_at":"2026-03-20T06:23:40.000Z","dependencies_parsed_at":"2023-10-16T06:25:45.819Z","dependency_job_id":"ed1c4c23-134a-469d-90c5-1bb3c3225f52","html_url":"https://github.com/matryer/moq","commit_stats":{"total_commits":174,"total_committers":35,"mean_commits":"4.9714285714285715","dds":0.5632183908045977,"last_synced_commit":"0bf2e8a069abaefdfd07e4902d204441cca17298"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/matryer/moq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matryer%2Fmoq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matryer%2Fmoq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matryer%2Fmoq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matryer%2Fmoq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matryer","download_url":"https://codeload.github.com/matryer/moq/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matryer%2Fmoq/sbom","scorecard":{"id":625250,"data":{"date":"2025-08-11","repo":{"name":"github.com/matryer/moq","commit":"31af695e859b89ed710ee12c07720cea3e656b68"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.4,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":7,"reason":"Found 22/29 approved changesets -- score normalized to 7","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/release.yml:1","Warn: no topLevel permission defined: .github/workflows/test.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/matryer/moq/release.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/matryer/moq/release.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/matryer/moq/release.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/matryer/moq/test.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/matryer/moq/test.yml/main?enable=pin","Warn: goCommand not pinned by hash: .github/workflows/test.yml:45","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   0 out of   1 goCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Packaging","score":10,"reason":"packaging workflow detected","details":["Info: Project packages its releases by way of GitHub Actions.: .github/workflows/release.yml:10"],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v0.5.3 not signed: https://api.github.com/repos/matryer/moq/releases/200034483","Warn: release artifact v0.5.2 not signed: https://api.github.com/repos/matryer/moq/releases/199758462","Warn: release artifact v0.5.1 not signed: https://api.github.com/repos/matryer/moq/releases/186880943","Warn: release artifact v0.5.0 not signed: https://api.github.com/repos/matryer/moq/releases/171772028","Warn: release artifact v0.4.0 not signed: https://api.github.com/repos/matryer/moq/releases/171610530","Warn: release artifact v0.5.3 does not have provenance: https://api.github.com/repos/matryer/moq/releases/200034483","Warn: release artifact v0.5.2 does not have provenance: https://api.github.com/repos/matryer/moq/releases/199758462","Warn: release artifact v0.5.1 does not have provenance: https://api.github.com/repos/matryer/moq/releases/186880943","Warn: release artifact v0.5.0 does not have provenance: https://api.github.com/repos/matryer/moq/releases/171772028","Warn: release artifact v0.4.0 does not have provenance: https://api.github.com/repos/matryer/moq/releases/171610530"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 27 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-21T06:12:52.355Z","repository_id":37709790,"created_at":"2025-08-21T06:12:52.355Z","updated_at":"2025-08-21T06:12:52.355Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31291147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"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":["codegen","golang","mocking","testing"],"created_at":"2024-07-30T20:01:52.890Z","updated_at":"2026-04-01T19:32:53.686Z","avatar_url":"https://github.com/matryer.png","language":"Go","readme":"![moq logo](moq-logo-small.png) [![build](https://github.com/matryer/moq/workflows/build/badge.svg)](https://github.com/matryer/moq/actions?query=branch%3Amaster) [![Go Report Card](https://goreportcard.com/badge/github.com/matryer/moq)](https://goreportcard.com/report/github.com/matryer/moq)\n\nInterface mocking tool for go generate.\n\n### What is Moq?\n\nMoq is a tool that generates a struct from any interface. The struct can be used in test code as a mock of the interface.\n\n![Preview](preview.png)\n\nabove: Moq generates the code on the right.\n\nYou can read more in the [Meet Moq blog post](http://bit.ly/meetmoq).\n\n### Installing\n\nTo start using latest released version of Moq, just run:\n\n```\n$ go install github.com/matryer/moq@latest\n```\n\nNote that Go 1.18+ is needed for installing from source. For using Moq with\nolder Go versions, use the pre-built binaries published with \n[Moq releases](https://github.com/matryer/moq/releases). \n\n### Usage\n\n```\nmoq [flags] source-dir interface [interface2 [interface3 [...]]]\n  -fmt string\n    \tgo pretty-printer: gofmt, goimports or noop (default gofmt)\n  -out string\n    \toutput file (default stdout)\n  -pkg string\n    \tpackage name (default will infer)\n  -rm\n    \tfirst remove output file, if it exists\n  -skip-ensure\n    \tsuppress mock implementation check, avoid import cycle if mocks generated outside of the tested package\n  -stub\n    \treturn zero values when no mock implementation is provided, do not panic\n  -version\n    \tshow the version for moq\n  -with-resets\n    \tgenerate functions to facilitate resetting calls made to a mock\n\nSpecifying an alias for the mock is also supported with the format 'interface:alias'\n\nEx: moq -pkg different . MyInterface:MyMock\n```\n\n**NOTE:** `source-dir` is the directory where the source code (definition) of the target interface is located.\nIt needs to be a path to a directory and not the import statement for a Go package.\n\nIn a command line:\n\n```\n$ moq -out mocks_test.go . MyInterface\n```\n\nIn code (for go generate):\n\n```go\npackage my\n\n//go:generate moq -out myinterface_moq_test.go . MyInterface\n\ntype MyInterface interface {\n\tMethod1() error\n\tMethod2(i int)\n}\n```\n\nThen run `go generate` for your package.\n\n### How to use it\n\nMocking interfaces is a nice way to write unit tests where you can easily control the behaviour of the mocked object.\n\nMoq creates a struct that has a function field for each method, which you can declare in your test code.\n\nIn this example, Moq generated the `EmailSenderMock` type:\n\n```go\nfunc TestCompleteSignup(t *testing.T) {\n\n\tvar sentTo string\n\n\tmockedEmailSender = \u0026EmailSenderMock{\n\t\tSendFunc: func(to, subject, body string) error {\n\t\t\tsentTo = to\n\t\t\treturn nil\n\t\t},\n\t}\n\n\tCompleteSignUp(\"me@email.com\", mockedEmailSender)\n\n\tcallsToSend := len(mockedEmailSender.SendCalls())\n\tif callsToSend != 1 {\n\t\tt.Errorf(\"Send was called %d times\", callsToSend)\n\t}\n\tif sentTo != \"me@email.com\" {\n\t\tt.Errorf(\"unexpected recipient: %s\", sentTo)\n\t}\n\n}\n\nfunc CompleteSignUp(to string, sender EmailSender) {\n\t// TODO: this\n}\n```\n\nThe mocked structure implements the interface, where each method calls the associated function field.\n\n## Tips\n\n* Keep mocked logic inside the test that is using it\n* Only mock the fields you need\n* It will panic if a nil function gets called\n* Name arguments in the interface for a better experience\n* Use closured variables inside your test function to capture details about the calls to the methods\n* Use `.MethodCalls()` to track the calls\n* Use `.ResetCalls()` to reset calls within an individual mock's context\n* Use `go:generate` to invoke the `moq` command\n* If Moq fails with a `go/format` error, it indicates the generated code was not valid.\n  You can run the same command with `-fmt noop` to print the generated source code without attempting to format it.\n  This can aid in debugging the root cause.\n\n## License\n\nThe Moq project (and all code) is licensed under the [MIT License](LICENSE).\n\nMoq was created by [Mat Ryer](https://twitter.com/matryer) and [David Hernandez](https://github.com/dahernan), with ideas lovingly stolen from [Ernesto Jimenez](https://github.com/ernesto-jimenez). Featuring a major refactor by @sudo-suhas, as well as lots of other contributors.\n\nThe Moq logo was created by [Chris Ryer](http://chrisryer.co.uk) and is licensed under the [Creative Commons Attribution 3.0 License](https://creativecommons.org/licenses/by/3.0/).\n\n","funding_links":["https://github.com/sponsors/matryer"],"categories":["Testing","开源类库","Go","testing","测试","Template Engines"],"sub_categories":["Mock","测试"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatryer%2Fmoq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatryer%2Fmoq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatryer%2Fmoq/lists"}