Skip to content
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

Generating a mock for external _test package #467

Open
mminklet opened this issue May 17, 2022 · 1 comment
Open

Generating a mock for external _test package #467

mminklet opened this issue May 17, 2022 · 1 comment

Comments

@mminklet
Copy link

I would imagine a lot of mocks are generated to be used in _test files, with _test package names. To generate one using mockery is a bit cumbersom. ie this is great mockery --inpackage --name NodeAndOptionsGetter but will generate a mock as the main package, meaning having to import it to *_test tests (not the end of the world I know)

To get the same mock, with the same MockNodeAndOptionsGetter name, in the same directory, with the same mock_ prefix, but with the _test suffix, and using the _test package, this is what you seemingly have to write:

mockery --output ./ --name NodeAndOptionsGetter --outpkg handler_test --filename mock_NodeAndOptionsGetter_test.go --structname MockNodeAndOptionsGetter

That's a lot of boilerplate, when tbh I would have thought the --testonly flag would do it all (which in fact on it's own is a compile error due to it not bing in a _test.go file). Is there a better way to do it that I'm not seeing?

Version

v2.10.0

@LandonTClipp
Copy link
Contributor

So there have been requests in the past to add a --packagesuffix option which I previously put on hold because I wasn't sure how popular such a feature would be, and to be honest it's not requested that much because in my experience most people write their test files to be in the same package as the source code. But, I know both standards are used variously in the community.

If you want to add a PR for that flag I think that'll solve your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants