Open relnod opened 6 years ago
Hi @relnod,
This won't work. The point of internal packages is that other packages do not get access to them. That includes their interfaces. Hence, you cannot generate a mock for those.
If you own that package yourself, you can move it out of internal
. Note though, that you might not want to do that, because it's probably internal for a reason. More generally speaking, I don't recommend mocking interfaces that are not supposed to be public interfaces.
I hope this helps, Peter
Hi @petergtz , I decided not to use an interface, where I was using it before. I'm still wondering though, why generating the mock in the internal package worked, as long as my project was in the normal $GOPATH, but didn't when I moved it outside. Also an error instead of a panic would have been nice :)
Hi @relnod,
Hm, I guess I'm having difficulties to really understand your use case. Could you provide a sample setup so I can reproduce this?
Definitely agree that an error would be better than a panic. Will improve that once I can reproduce your problem.
Hi, I got the following error when generating mocks outside of the GOPATH:
panic: Loading input failed: exit status 1 caused by: prog.go:14:2: use of internal package not allowed
goroutine 1 [running]: github.com/petergtz/pegomock/pegomock/filehandling.GenerateMockSourceCode(0xc42000c5c0, 0x2, 0x2, 0x7fff0d647602, 0x4, 0x0, 0x0, 0xc420000100, 0x7a84a0, 0xc420098010, ...) /home/----/go/src/github.com/petergtz/pegomock/pegomock/filehandling/filehandling.go:108 +0x5c4 github.com/petergtz/pegomock/pegomock/filehandling.GenerateMockFile(0xc42000c5c0, 0x2, 0x2, 0x7fff0d6475ed, 0xa, 0x7fff0d647602, 0x4, 0x0, 0x0, 0x0, ...) /home/----/go/src/github.com/petergtz/pegomock/pegomock/filehandling/filehandling.go:62 +0xc3 github.com/petergtz/pegomock/pegomock/filehandling.GenerateMockFileInOutputDir(0xc42000c5c0, 0x2, 0x2, 0xc42001a0f4, 0x20, 0x7fff0d6475ed, 0xa, 0x7fff0d647602, 0x4, 0x0, ...) /home/----/go/src/github.com/petergtz/pegomock/pegomock/filehandling/filehandling.go:39 +0x162 main.Run(0xc4200a0000, 0x8, 0x8, 0x7a84a0, 0xc420098010, 0xc42013c000, 0xc4200200c0) /home/----/go/src/github.com/petergtz/pegomock/pegomock/main.go:80 +0x160a main.main() /home/----/go/src/github.com/petergtz/pegomock/pegomock/main.go:35 +0x90
It does work with a non internal package and it also works perfectly when I'm generating the mocks in the normal package (inside GOPATH).