You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, to define which types (not packages) to generate mocks for using the new configuration syntax, there seem to be three options: specify each type, set all: true, or set include-regex to a regular expression. However, negating a regular expression is not possible in general, and so there is no way to configure mockery to generate mocks for all types except certain ones.
In my particular case, I have a type like the following:
typeOptionfunc(*privateStructType)
I configure mockery to generate mocks in another package, and so it is impossible to have a mock for this type. However, without enumerating all of the other interface types instead, I see no way to disable mock generation for this type. What I'd like to see is something like an exclude-regex option (the inverse of include-regex), an ignore type-specific option, or some similar mechanism to prevent this type from being mocked.
A temporary solution might have been to specify a never-used build tag on that type only, but when trying that, I ran into #691 instead.
Mockery Version
% mockery --version08 Oct 23 17:06 EDT INF couldn't read any config file version=v2.34.208 Oct 23 17:06 EDT INF Starting mockery dry-run=false version=v2.34.208 Oct 23 17:06 EDT INF Using config: dry-run=false version=v2.34.2v2.34.2
Golang Version
% go versiongo version go1.21.2 darwin/arm64
Installation Method
Binary Distribution
Docker
brew
go install
Other: [specify]
Steps to Reproduce
Not a bug, but here's my mockery config for illustration (exact package name is redacted):
I was waiting for someone to send in a request for this :D I have no concerns with it. When an interface matches both the include and exclude regex, we should exclude the interface. I think this will be very easy to do, PRs are welcome!
kbolino
added a commit
to kbolino/mockery
that referenced
this issue
Oct 9, 2023
Description
Currently, to define which types (not packages) to generate mocks for using the new configuration syntax, there seem to be three options: specify each type, set
all: true
, or setinclude-regex
to a regular expression. However, negating a regular expression is not possible in general, and so there is no way to configure mockery to generate mocks for all types except certain ones.In my particular case, I have a type like the following:
I configure mockery to generate mocks in another package, and so it is impossible to have a mock for this type. However, without enumerating all of the other interface types instead, I see no way to disable mock generation for this type. What I'd like to see is something like an
exclude-regex
option (the inverse ofinclude-regex
), anignore
type-specific option, or some similar mechanism to prevent this type from being mocked.A temporary solution might have been to specify a never-used build tag on that type only, but when trying that, I ran into #691 instead.
Mockery Version
Golang Version
Installation Method
Steps to Reproduce
Not a bug, but here's my mockery config for illustration (exact package name is redacted):
The text was updated successfully, but these errors were encountered: