MOCKGEN(1)

πŸ’– MOCKGEN(1) πŸ’–

okay so bestie, gather round, we're talking about mockgen β€” a User Command that lives in your terminal and is genuinely so good at its job. Go devs, this one's for you 🫢


✨ NAME ✨

mockgen β€” generate source for mock class of a Go source πŸ’…


🌸 DESCRIPTION 🌸

The mockgen command is used to generate source code for a mock class given a Go source file containing interfaces to be mocked. literally its whole personality. it reads interfaces, it writes mocks, it slays.

mockgen has two modes of operation: source and reflect. two vibes. pick one. iykyk.

Source mode generates mock interfaces from a source file. It is enabled by using the -source flag. Other flags that may be useful in this mode are -imports and -aux_files. Example:

mockgen -source=foo.go [other options]

Reflect mode generates mock interfaces by building a program that uses reflection to understand interfaces. It is enabled by passing two non-flag arguments: an import path, and a comma-separated list of symbols. Example:

mockgen database/sql/driver Conn,Driver
  • -aux_files="" β€” (source mode) Comma-separated pkg=path pairs of auxiliary Go source files.
  • -debug_parser=false β€” Print out parser results only. that's it, that's the whole thing πŸ›
  • -destination="" β€” Output file; defaults to stdout. no file? cool, it just yells into your terminal.
  • -exec_only="" β€” (reflect mode) If set, execute this reflection program.
  • -imports="" β€” (source mode) Comma-separated name=path pairs of explicit imports to use.
  • -package="" β€” Package of the generated code; defaults to the package of the input with a 'mock_' prefix. cute little auto-nickname, love that for it ✨
  • -prog_only=false β€” (reflect mode) Only generate the reflection program; write it to stdout.
  • -self_package="" β€” If set, the package this mock will be part of.
  • -source="" β€” (source mode) Input Go source file; enables source mode.

πŸ¦‹ okay so. it says it again. πŸ¦‹

bestie i need you to know this is not me being lazy β€” the manpage genuinely says all of this a second time, word for word. so here it is again, verbatim, because i keep every detail and i do not skip. periodt. πŸ’€

mockgen has two modes of operation: source and reflect.

Source mode generates mock interfaces from a source file. It is enabled by using the -source flag. Other flags that may be useful in this mode are -imports and -aux_files. Example:

mockgen -source=foo.go [other options]

Reflect mode generates mock interfaces by building a program that uses reflection to understand interfaces. It is enabled by passing two non-flag arguments: an import path, and a comma-separated list of symbols. Example:

mockgen database/sql/driver Conn,Driver
  • -aux_files="" β€” (source mode) Comma-separated pkg=path pairs of auxiliary Go source files.
  • -debug_parser=false β€” Print out parser results only.
  • -destination="" β€” Output file; defaults to stdout.
  • -exec_only="" β€” (reflect mode) If set, execute this reflection program.
  • -imports="" β€” (source mode) Comma-separated name=path pairs of explicit imports to use.
  • -package="" β€” Package of the generated code; defaults to the package of the input with a 'mock_' prefix.
  • -prog_only=false β€” (reflect mode) Only generate the reflection program; write it to stdout.
  • -self_package="" β€” If set, the package this mock will be part of.
  • -source="" β€” (source mode) Input Go source file; enables source mode.

and that's the whole page, bestie!! go forth and mock responsibly πŸ‘‘

this edition is dated September 2015, and it's page MOCKGEN(1) of the manual β€” same title up top, same title down at the bottom, full circle moment πŸŽ€

later, legend πŸ’–βœ¨πŸ¦‹