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
Invalid mock generated with the same package names #291
Comments
What version of go are you using in |
I can reproduce this issue as you describe. I'm looking for a possible cause. |
So I added some debug messages and discovered that mockery is skipping this explicitly:
Although, it's a bit mysterious to me that even though it says it's skipping it, the import is still inserted somehow. That I don't understand. |
Additionally, I found the commit that caused this bug: d9507cd5 I don't have time to fix this today but at least I know what the problem is. I will fix the bug and write two unit tests to make sure this doesn't happen. |
Awesome thanks for looking into it so quickly. I would try and help more but I can't figure out how to reproduce it from the source code, only the compiled binaries. Here is the version of go I was using
|
Adding a few logging messages to see if we can catch why this is happening. Making a new build now, will see if this highlights any issues. |
I have discovered how to re-create the issue when building from source! When the formatter runs it can add/remove imports and it will add the import when build locally for some reason. So this line needs to be changed to the following so things are consistent. Still trying to track down how to fix the issue properly. https://github.com/vektra/mockery/blob/master/pkg/generator.go#L662 opt := &imports.Options{Comments: true, FormatOnly: true} |
…package would not get included in the mock
Fixing #291 where a different import with the same name as the package would not get included in the mock
…e package would not get included in the mock"
Revert "Fixing #291 where a different import with the same name as the package would not get included in the mock"
Well that is a bummer it caused other issues. I guess this ticket should be re-opened for now then. |
I faced the same issue. I use the latest docker image to generate mocks. Mocked interface is in package |
Have you guys fixed that issue yet? Because it's still present in the current version. Yes, running I was hoping aliasing would help, but it isn't (it should?) |
Fix: avoid package name collision with inPackage (#291)
Using either 1.1.2 or 2.0.0-alpha.13 release builds of mockery we have the following issue
cloudformation/interface.go
main.go
generates a mock like like the following when using
mockery -all -testonly -inpkg
You can see the import for cloudformation is missing and in turn the go reports undefined: cloudformation in the mock file.
It seems like when the cloudformation directory is at the root the issue cannot be re-created. When mockery is built from source either via
go get
or cloning andgo install
this issue seems to go away and the import is generated properly. As installing is not supported usinggo get
anymore our mocks are no longer generating properly.The text was updated successfully, but these errors were encountered: