Closed pasztorpisti closed 6 years ago
This also works in the following scenario:
github.com/anyuser/pkg1/file1.go
type A interface {
Method1()
}
github.com/anyuser/pkg1/file2.go
type B interface {
A
}
Just to make explicit the difference here: Two separate files, but same package produces the same issue.
mockgen -source=pkg1/file2.go -package pkg1 -aux_files pkg1=pkg1/file1.go -destination pkg1/file2_mock.go
The above produces the 'unknown embedded interface' error.
It can also be resolved as you described, by the following:
type B interface {
pkg1.A
}
But again, thats invalid Golang code.
Looking into it more, I found this TODO in the source code.
https://github.com/golang/mock/blob/747e9e6390e12b0d987c261bdc89a51e76b9f5fc/mockgen/mockgen.go#L18
Both given examples above work now.
@balshetzer Just checked. Not working. The only way to solve this case is to use reflect mode.
As I said in #178, The aux_files flag needs to specify the full package path.
Here are my test files (2 packages):
github.com/anyuser/pkg1/pkg1.go:
github.com/anyuser/pkg2/pkg2.go:
If you run
go generate
onpkg2
then you get the following error message:Note that mock generation succeeds if you go to
pkg1
and embed theE
interface intoI
by prefixing it with the package namepkg1.E
but that turnspkg1.go
into invalid go code that doesn't compile.