You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"testing""github.com/warmans/example/mocks"//import the mocks subpackage
)
funcTestDoSomethingDoesSomething() {
mock=new(mocks.MyInterface) //create the mock
}
Couple of issues: there is import recursion which causes a import cycle not allowed in test error. Also Go seems to be a bit funny about importing and using main anyway.
I am able to work around the problem by supplying the inpkg=true flag but it seems cleaner to have the mocks subpackage.
Thanks
The text was updated successfully, but these errors were encountered:
There is simply not way to handle this other than using inpkg, other than you don't put everything in the main namespace. So either just use inpkg or reorg the code to not use main (I only put the bare minimum in main).
Hi,
I don't know if this is a stupid question or not but is it possible to generate mocks into a mocks "subpackage" when your interfaces are in main?
e.g.
main.go
Will generate something like:
mocks/MyInterface.go
which means the test looks like this:
main_test.go
Couple of issues: there is import recursion which causes a
import cycle not allowed in test
error. Also Go seems to be a bit funny about importing and using main anyway.I am able to work around the problem by supplying the
inpkg=true
flag but it seems cleaner to have the mocks subpackage.Thanks
The text was updated successfully, but these errors were encountered: