Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ mockgen database/sql/driver Conn,Driver
mockgen . Conn,Driver
```

### Batch mode

Batch mode works similarly to package mode, but allows generating mocks for multiple packages at once.
This is especially useful in large codebases that call mockgen repeatedly,
as it allows mockgen to parse the code only once, making the generation process shorter.

To use batch mode you need to prepare a YAML file.
The file provides a list of package and interface names pairs, called generation "targets".
It also allows specifying flags for all packages (in the `generator` section), or for individual packages.
Field names are identical with commandline flags used in package mode.

The file structure is as follows:

```yaml
generator:
# package mode flags to use for all packages:
typed: true
copyright_file: copyright.txt
targets:
- target: database/sql/driver Conn,Driver
- target: github.com/example/example/mypackage Client,Server
# package-specific flags:
destination: example/example/mypackage/mocks/generated.go
write_generate_directive: true
```

### Flags

The `mockgen` command is used to generate source code for a mock
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ require (
github.com/stretchr/testify v1.9.0
golang.org/x/mod v0.18.0
golang.org/x/tools v0.22.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/yuin/goldmark v1.4.13 // indirect
golang.org/x/sync v0.7.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading