-
Notifications
You must be signed in to change notification settings - Fork 606
Unable to generate mocks in reflect mode #494
Comments
The error message is due to I would assume the reason you started seeing it at an indeterminate time has to do with them slowly making modules the default behavior in new versions of golang. How to fix this is a bit more tricky. The golang program generated by reflection mode depends on There are probably some hacky work arounds like forcing the import with an cc @codyoss |
As super hacky work around you can copy the directory |
I think this is related to recent changes in Go tooling. Adding |
Thanks! |
I think what needs to happen now is some discussion about how to conceptually solve this problem; any input would be welcome and appreciated. The basic overview (IIUC @codyoss can correct me) is that during reflection mode we dynamically generate some golang source code for a new main program. This main program, the reflection program, is the heart of what makes reflection mode work. The source code is written out by Problem we are hitting is in the dependency management; the reflection program requires When the So we essentially have two different build environments that require different dependencies. |
One of the problems is that the error message is so cryptic and unergonomic, it is impossible to figure out why this is happening. And the reason why (as comments above explain) is that that the My workaround (strangely enough) was to remove the whole |
After looking more into this issue I am not sure there is too much we can do about this. For now I will treat this as a documentation issue and add some notes in the readme. |
If documentation is the solution you could add a pointer to the readme in the error as this is a known problem and the error message printed is a dead end for the user. |
@caskey That is a great idea, done! |
Hi there, any chance this has changed since last year? I'm new to GoMock but ran into this. Thanks for all you do for Go and the OSS community in general! |
Hey I also came across this issue today, Looks like installing the The ERROR I had
SOLUTIONInstall the package using the following command go get github.com/golang/mock/ The output should be like this go: upgraded github.com/golang/mock v1.4.4 => v1.6.0 After so ran the mockgen command and everything worked. Notice Change command below to one that matches your project mockgen -destination db/mock/store.go github.com/escalopa/go-bank/db/sqlc Store As a result you should see the the following files have been updated
This is how to worked for me, Wish this might help 😄 |
Ran into this and resolve it by creating
Then I was able to:
|
thnks it worked for me |
Actual behavior A clear and concise description of what the bug is.
My project uses Go modules, but due to the CI restrictions we also make use of the
vendor
folder.So, our modules are synced by
go mod tidy && go mod vendor
command.While using
mockgen
in areflect
mode, I'm unable to generate mocks. Can't pinpoint exactly when this became broken as this was working fine before, but it doesn't anymore.The error message:
Seems to be somewhat similar to the #423 but the proposed solution didn't work for me.
Expected behavior A clear and concise description of what you expected to
happen.
Mocks should've been generated fine.
To Reproduce Steps to reproduce the behavior
I've published a test project which can be used to reproduce the issue.
mockgen
is called during thego:generate
directive at internal/service/doc.go:The interface to generate the mocks upon is pretty simple and is stored at internal/client/contract.go:
So, the steps are:
vendor
:a. Run
go mod tidy && go mod vendor
to clean up the dependenciesb. Run
go generate ./...
once - it'll work fine,mocks_test.go
file will be generatedc. Delete
mocks_test.go
file to reproduce the errorgo generate ./...
It seems that the fact that
vendor
contains dependencies somehow breaks the ability ofmockgen
to generate the mocks, since the vendor-less mode works fine.Additional Information
go env
output:The text was updated successfully, but these errors were encountered: