-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--name
doesn't accept regex values
#684
Comments
The first question I have is whether or not you are using the |
Yes, we are using the packages config: packages:
github.com/xxxxx/xxxxx:
config:
recursive: True
inpackage: True
case: underscore
We are ok not using |
You're correct there is no equivalent, so you have to explicitly list the interfaces you want, or just do |
Maybe something like this: packages:
github.com/xxxxx/xxxxx:
config:
recursive: True
inpackage: True
all: True
include: ".*Client"
exclude: "FooClient" 🤷🏻 |
Would you be open to a PR for this? In our use case, generating all mocks increases package size by nearly 100% and takes ~7x more time than filtering out the interfaces before generation (I used a simple |
Hey @LandonTClipp how are you doing? Firstly; congrats on the work you have done with this project, you've done so much to keep it fresh and up to date. Kudos. We're in a similar situation as @leaanthony-sc; I would like to upgrade to v3, but are struggling with some of the new breaking changes. We have a very large repository that holds all of our protocol buffer services for our entire system, very similar to Google's APIs: https://github.com/googleapis/googleapis When we generate the Go clients we have 100s (maybe 1000s) of gRPC Clients that get generated. Example: https://github.com/grpc/grpc-go/blob/master/examples/helloworld/helloworld/helloworld_grpc.pb.go#L42 These clients are all auto-generated (ie. have "DO NOT EDIT") and would require a lot of work (script-able... but still a pain) to have an explicit list. These files/packages contain all the Service interfaces too which we do not need to mock so I would expect that many people would want to mock gRPC clients (perfect use-case for mockery) so would be good to cater to this. What do you think? |
Hi folks, and @rogchap. I'm okay with someone implementing this. It seems like the need is pretty strong so that's okay. If you want to put in a PR that implements the config I suggested then I will accept it! |
+1 on this being a much needed feature when using In terms of how it is implemented / setup, is there a way we can leverage the fact that |
@benvernier-sc I'm not sure if we can leverage that. The config model has the name of the interface as part of the What would you propose instead of the example I posted? Since I'm not sure I understand your ask. |
@LandonTClipp Yes, my instinctive thought when reading the docs and seeing that packages:
github.com/xxxxx/xxxxx:
config:
recursive: True
inpackage: True
interfaces:
"{{ matchString(\".*(Suffix1|Suffix2)\", .InterfaceName) }}": |
Hmm, that would complicate some things. There are various parts of the code that assume they can map a single interface name in It would be a matter of writing two conditionals for the |
That makes sense, and a similar conclusion to what I had found when I looked at the implementation, I was mainly sharing an other perspective as to what I intuitively thought would be the way to achieve this. Regarding the suggested |
It's a good point that it might be confusing. I wonder if maybe specifying |
After further thought I think the best way forward would be to use a parameter named If someone wants to volunteer to implement this then I'd be happy to let you have it. Otherwise it might take me a couple weeks to do it. |
Description
Running mockery with
--name "<regex>"
results in the following error:Cannot specify --filename or --structname with regex in --name
, even when no config or flag has been set for either of these 2 options.I've tracked this bug down to this section of code. It appears that the check after a valid regex compilation looks for non-zero values for
r.Config.Filename
andr.Config.StructName
, and if either are set then it raises a fatal error. The problem appears to be that a default value is set forr.Config.Filename
so this check will always fail.Mockery Version
v2.32.3
Golang Version
v1.20.7
Installation Method
Steps to Reproduce
--name ".*Client"
Expected Behavior
Mocks generated for all interfaces found with a suffix of
Client
Actual Behavior
Fatal error message:
Cannot specify --filename or --structname with regex in --name
The text was updated successfully, but these errors were encountered: