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

Allow counterfeiting unexported interface methods. #112

Merged
merged 3 commits into from
Jun 3, 2019
Merged

Allow counterfeiting unexported interface methods. #112

merged 3 commits into from
Jun 3, 2019

Conversation

davidnewhall
Copy link
Contributor

@davidnewhall davidnewhall commented Feb 10, 2019

Hello,

I love this application and I use it religiously for many projects.

Recently I attempted to counterfeit an unexpected interface with only unexported methods. This caused counterfeiter to create code with duplicate methods and fields; it failed to compile.

This contribution is simply an example of how I worked around the problem. My feelings will be unaffected if you choose not to accept this. I just figured showing one version of a solution to the problem would help explain what I've run into. I'll be highly appreciative if you can find a way to allow unexported interfaces to be properly counterfeited.

This contribution, although a little lengthy, shows where I ran into this problem: golift/securityspy#18 - You can see the new interface and the api_fakes file that was generated with this code. I noted my changes (to make this work locally) at the top of the file.

Warm regards,
-david

@davidnewhall
Copy link
Contributor Author

That seems like a very reasonable suggestion. I haven't looked at the source of this project for more than a couple of minutes at this point, and didn't dig into the templating methods at all. If a contribution with those changes seems acceptable, I'll re-work this pull request.

I have at least four more projects in which I need to override local interfaces. This is a feature I cannot personally live without; it makes testing my methods so dang easy.

Is there any recommendation around augmenting the package name? In the case of mocking a local interface, it makes little sense to make the package outside of the package it mocks. Currently I manually change that 1 line in the counterfeiter output file.

Thanks!

@davidnewhall
Copy link
Contributor Author

Made the recommend changes. Seems good to me, and still creates usable fakes for unexported methods.

@joefitzgerald joefitzgerald merged commit db49161 into maxbrunsfeld:master Jun 3, 2019
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

Successfully merging this pull request may close these issues.

3 participants