golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.26k stars 608 forks source link

mockgen command fails when source code of gomock is contained in vendor directory #143

Closed berndwarmuth closed 6 years ago

berndwarmuth commented 6 years ago

I am using mockgen to generate mocks for my interfaces. It all works fine, however as soon as i include the sources for gomock into the vendor directory using golang/dep, the mockgen command fails with the following error message:

Loading input failed: gob: name not registered for interface: "github.com/triggetry/goproj/vendor/github.com/golang/mock/mockgen/model.PredeclaredType"

Any ideas? Thanks

adampointer commented 6 years ago

I have been banging my head against this one for hours. I saw your issue and I realised exactly what the issue is, so thanks!

Maybe it's the same for you, I use dep to get my dependencies and it wants to install the v1.0.0 tag of github.com/golang/mock while go getting to install the mockgen binary will give you the master branch. I think its the two differing versions which is causing the problem. I changed Gopkg.toml to install master not the tagged release, and it works.

I hope this helps you as much as it has helped me!!

berndwarmuth commented 6 years ago

Thank you adam, this fixed the problem for me as well :-)

prateek commented 5 years ago

for posterity, an alternative way to solve this is to tell dep to force the missing imports in it's SAT solver.

I added the following to Gopkg.toml:

# NB: need the following to ensure we pull down mockgen despite not calling the code
# directly in the repo. mockgen (the tool) requires the source to be present or its :(
required = ["github.com/golang/mock/mockgen"]

This lets you specify whatever version/revision of mock you want to be on, which you might prefer over branch = "master".