-
Notifications
You must be signed in to change notification settings - Fork 31
Allow creating mocks for *_test package interfaces #88
Copy link
Copy link
Open
Description
In my code base, I use many private interfaces to prevent package pollution.
I have an interface in my source code:
package auth
type tokenRetriever interface {
Token() (string, error)
}
func SomeThing(retriever tokenRetriever) {
// do stuff
}package auth_test
type Cache interface {
Token() (string, error)
}
// Test Cases HereHowever, I cannot use pegomock to generate a mock for the given interface even though it is exported. I dont want to change the package my test file to be auth as it allows direct access to package members (we want to do API only testing and remove dependency on source code).
panic: Loading input failed: exit status 1 caused by:
prog.go:14:2: cannot find package "github.com/<dir>/<project>/internal/auth_test" in any of:
/Users/james.popadak/go/src/github.com/<dir>/<project>/vendor/github.com/<dir>/<project>/internal/auth_test (vendor tree)
/usr/local/Cellar/go/1.12.5/libexec/src/github.com/<dir>/<project>/internal/auth_test (from $GOROOT)
/Users/james.popadak/go/src/github.com/<dir>/<project>/internal/auth_test (from $GOPATH)
goroutine 1 [running]:
github.com/petergtz/pegomock/pegomock/filehandling.GenerateMockSourceCode(0xc0000fc480, 0x2, 0x2, 0x0, 0x0, 0xc0001061a0, 0x9, 0x0, 0x0, 0xc000140000, ...)
/Users/james.popadak/go/pkg/mod/github.com/petergtz/pegomock@v2.3.0+incompatible/pegomock/filehandling/filehandling.go:110 +0x614
github.com/petergtz/pegomock/pegomock/filehandling.GenerateMockFile(0xc0000fc480, 0x2, 0x2, 0xc000140070, 0x64, 0x0, 0x0, 0xc0001061a0, 0x9, 0x0, ...)
/Users/james.popadak/go/pkg/mod/github.com/petergtz/pegomock@v2.3.0+incompatible/pegomock/filehandling/filehandling.go:64 +0xdd
github.com/petergtz/pegomock/pegomock/filehandling.GenerateMockFileInOutputDir(0xc0000fc480, 0x2, 0x2, 0xc000020004, 0x51, 0x0, 0x0, 0x0, 0x0, 0xc0001061a0, ...)
/Users/james.popadak/go/pkg/mod/github.com/petergtz/pegomock@v2.3.0+incompatible/pegomock/filehandling/filehandling.go:40 +0x17f
main.Run(0xc000012100, 0x4, 0x4, 0x141d820, 0xc000010018, 0x141d800, 0xc000010010, 0xc0001320f0, 0xc000142000)
/Users/james.popadak/go/pkg/mod/github.com/petergtz/pegomock@v2.3.0+incompatible/pegomock/main.go:116 +0x2359
main.main()
/Users/james.popadak/go/pkg/mod/github.com/petergtz/pegomock@v2.3.0+incompatible/pegomock/main.go:37 +0xa8
auth_suite_test.go:9: running "pegomock": exit status 2
Process finished with exit code 1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels