Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading Input Failed: prog.go:14:2: use of internal package not allowed #64

Open
relnod opened this issue Jun 29, 2018 · 3 comments
Open

Comments

@relnod
Copy link
Contributor

relnod commented Jun 29, 2018

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).

@petergtz
Copy link
Owner

petergtz commented Jul 2, 2018

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

@relnod
Copy link
Contributor Author

relnod commented Jul 10, 2018

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 :)

@petergtz
Copy link
Owner

petergtz commented Jul 11, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants