ernesto-jimenez / gogen

A set of go packages and command line tools to generate Go code
MIT License
96 stars 13 forks source link

goautomock failed to find dependency in the vendor directory #5

Closed nikolay-turpitko closed 6 years ago

nikolay-turpitko commented 7 years ago

I've tried to use goautomock on interface, dependency of which resides in the vendor directory. Tool replied with "could not import xxxx not in $GOPATH".

go version go1.7.3 linux/amd64 glide version v0.12.3

morriswinkler-simple commented 7 years ago

i have similar issues, but outside the vendor, it has problems for example with

github.com/lib/pq/oid/gen.go the file uses // +build ignore which is ignored by automock

secondly it also includes platform files _windows _darwin but all of them, so variables get redeclared

nikolay-turpitko commented 7 years ago

@morriswinkler-simplesurance

For the moment I switched to mockery (https://github.com/vektra/mockery) which was mentioned by Ernesto in his blog post: https://blog.gopheracademy.com/advent-2015/reducing-boilerplate-with-go-generate/. It may be more complex internally, but it works for me. Try it, may be it'll work for you as well.

sbourlon commented 7 years ago

I have the same problem on Windows 10.

I think the problem is at pkg, err := i.fsPkg(path) (https://github.com/ernesto-jimenez/gogen/blob/master/importer/importer.go#L37) because the code is passing a path to the function func (i *customImporter) fsPkg(pkg string) which I guess expects the package name and not a path. As a result, the function fsPkg calls func gopathDir(pkg string) (https://github.com/ernesto-jimenez/gogen/blob/master/importer/importer.go#L45) which joins GOPATH/src and a path instead of the name.