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
Fix infinity mocking caused interface in mock #472
Conversation
Thank you so much for the PR, what a silly issue. Your proposed solution is kind of hacky but to be honest I cannot think of a better way to do it, as you need some kind of magic string to determine what interface was generated by mockery (and thus to ignore)... so this might be what we have to do. |
pkg/generator.go
Outdated
@@ -24,6 +24,8 @@ import ( | |||
"golang.org/x/tools/imports" | |||
) | |||
|
|||
const mockConstructorParamTypeNamePrefix = "_testingT_6ImLfpP5pg_" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call this mockConstructorTestingTNamePrefix
. Also, what's your motivation for making this private? It seems to me like it might be useful for linters to know what this type is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sure, I didn't really think about it. Sure, I'll update this to be more readable (I was aiming for uniqueness).
Yeah, I was really surprised to see hundreds of "mocks" directories. π€£
The best way, in my opinion, would be to extend the |
942f75e
to
0a143de
Compare
Codecov Report
@@ Coverage Diff @@
## master #472 +/- ##
=======================================
Coverage 71.56% 71.56%
=======================================
Files 6 6
Lines 1252 1252
=======================================
Hits 896 896
+ Misses 310 309 -1
- Partials 46 47 +1
Continue to review full report at Codecov.
|
0a143de
to
f04b040
Compare
@@ -24,6 +24,8 @@ import ( | |||
"golang.org/x/tools/imports" | |||
) | |||
|
|||
const mockConstructorParamTypeNamePrefix = "mockConstructorTestingT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I actually didn't mean we couldn't use the random string idea. I'm just curious if it would make sense to make it MockConstructorTestingT
instead of mockConstructorTestingT
. I'm thinking mainly of linters being able to see the interface (I don't actually know if they won't see unexported interfaces). This is fine for now though, we can always change it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, I've never written a linter for Go before :D But I'm quite sure they don't care about stuff being exported or not - that would make them a shitty linter IMO π€£ But yeah, making it public later is easy :)
Description
When you fixed this issue #461 you introduced an annoying bug. π You can't run mockery multiple times as it will generate mocks of the mocks themselves because each mock now contains an interface (which is itself a candidate for mock generation).
Two examples; first with
--keep-tree
(infinite mocks) and second without (error on third run):Type of change
Version of Golang used when building/testing:
How Has This Been Tested?
Run the tests + tested manually against a dummy package.
Checklist