- Notifications
You must be signed in to change notification settings - Fork0
Type-safe, fast and handy alternative gomock generator
License
NotificationsYou must be signed in to change notification settings
skipor/gmg
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
gmg
is type-safe, fast and handy alternativeGoMock generator.
Up to 4x times faster than
mockgen
in reflect modemockgen
builds program depending on your interface and analyse it withreflect
- that is much extra work!gmg
loads ast and type info usinggo/packages which doesn't require build and run executable .
Type-safe
gomock.Call
wrapped soDo
,Return
andDoAndReturn
arguments are concrete types, but justargs ...interface{}
- Autocomplete works perfect!
- After mock regeneration all type inconsistency in tests are visible in IDE as type check errors.
Robust
- Generation usually works, even when compilation is not.
Easy to use
There are sensible defaults for source package (
.
) and destination (./mocks
).That is, usually, you need only to specify the interface name to mock.
go install github.com/skipor/gmg@latest
GO111MODULE=on go get github.com/golang/mock/mockgen@latest
Please fix a specific version, if you usegmg
in automation.
$ gmg --helpgmg is type-safe, fast and handy alternative GoMock generator. See details at: https://github.com/skipor/gmgUsage: gmg [--src <package path>] [--dst <file path>] [--pkg <package name>] <interface name> [<interface name> ...]Flags: --all Select all interfaces in package. When called from //go:generate comment then package kind selected automatically: primary - other than *_test.go files; test - *_test.go files; black-box-test - package *_test --all-file Select all interfaces in current file, when called from //go:generate comment . --debug Verbose debug logging. -d, --dst string Destination directory or file relative path or pattern. '{}' in directory path will be replaced with the source package name. '{}' in file name will be replaced with snake case interface name. If no file name pattern specified, then '{}.go' used by default. Examples: ./mocks ./{}mocks ./mocks/{}_gomock.go ./mocks_test.go # All mocks will be put to single file. (default "./mocks") -p, --pkg string Package name in generated files. '{}' will be replaced with source package name. By default, --dst package name used, or 'mocks_{}' if --dst package is not exist. Examples: mocks_{} # mockgen style {}mocks # mockery style -s, --src string Source Go package to search for interfaces. Absolute or relative. Maybe third-party or standard library package. Examples: . ./relative/pkg github.com/third-party/pkg io (default ".") --version Show version and exit
- Large interface - 4x faster
mockgen --destination ./mocks/interface.go k8s.io/client-go/kubernetes
: 3.022 secondsgmg --src k8s.io/client-go/kubernetes Interface
: 0.741 seconds - Small interface - 2x faster
mockgen --destination ./mocks/writer.go io Writer
: 0.676 secondsgmg --src io Writer
: 0.321 seconds
Measured on MacBook Pro (15-inch, 2017) 4 core i7, 16G with warmgo build
cache.
About
Type-safe, fast and handy alternative gomock generator
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published