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

Add option to generate exported mock type for internal interfaces #191

Closed
pkosiec opened this issue Mar 28, 2018 · 3 comments · Fixed by #357
Closed

Add option to generate exported mock type for internal interfaces #191

pkosiec opened this issue Mar 28, 2018 · 3 comments · Fixed by #357

Comments

@pkosiec
Copy link

pkosiec commented Mar 28, 2018

#Hi,
Great tool, I really like it! Is there a possibility to add a new option like -exported=true, which will make internal interfaces exported?
Please consider an example:

//go:generate mockery -name=foo -output=automock -outpkg=automock -case=underscore -exported=true
type foo interface {
	Bar(name string) (string, bool, error)
}

It could generate a mock type in automock package with a name Foo, which is easy to use in test files.

Alternative:
It could generate a constructor for this type, which can be used from outside of the automock package.

@LandonTClipp
Copy link
Contributor

I really like this idea. I'll tag this for consideration.

@matcornic
Copy link

matcornic commented May 25, 2020

This option would help me. I have a problem when the mocks on private interface are generated in a different folder than the origin package. It tries to import to origin interface but compilation of the generated mock fails as the interface is private and the import comes from another package.
As I'm not using the private interface, this would be a nice option to have to avoid the problem. The root cause could be fixed though, but maybe in another issue ? tell me @LandonTClipp :)

Edit: I just looked at #234 (I'll try it thanks. But it's a workaround in my opinion)
Edit 2: I'm not using -name option, so I cannot use -filename option (name of generated file (only works with -name and no regex)

@LandonTClipp
Copy link
Contributor

@matcornic Adding this feature would be pretty trivial. The provided example in the OP with -exported=true would work well enough, PRs are welcome, I'm not sure if I will have time to get to this this month, but we'll see.

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