pegomock: pegomock generate panics with `cannot find module for path`
I’m following the docs to the best of my ability, but can’t seem to get around this issue (note I scrubbed the module and user names from the path):
~/go/bin$ wget --quiet -O pegomock_2.2.0 https://github.com/petergtz/pegomock/releases/download/v2.2.0/pegomock_2.2.0_linux_x86_64
~/go/bin$ chmod a+x pegomock_2.2.0
~/go/bin$ cd ~/VisualStudioCode/go/<module>/core/
~/VisualStudioCode/go/<module>/core$ go get github.com/petergtz/pegomock@v2.2.0
go: finding github.com/petergtz/pegomock v2.2.0
go: finding github.com/onsi/gomega/format latest
~/VisualStudioCode/go/<module>/core$ grep -n2 "UUIDGen interface" core.go
28-
29-// UUIDGen is an interface for a type that generates random UUIDs.
30:type UUIDGen interface {
31- GetUUID() uuid.UUID
32-}
~/VisualStudioCode/go/<module>/core$ pegomock_2.2.0 generate UUIDGen
panic: Loading input failed: exit status 1 caused by:
build command-line-arguments: cannot find module for path _/home/<user>/VisualStudioCode/go/<module>/VisualStudioCode/go/<module>/core
goroutine 1 [running]:
github.com/petergtz/pegomock/pegomock/filehandling.GenerateMockSourceCode(0xc000094c80, 0x2, 0x2, 0x0, 0x0, 0xc000080642, 0x9, 0x0, 0x0, 0x0, ...)
/Users/pego/workspace/go/src/github.com/petergtz/pegomock/pegomock/filehandling/filehandling.go:110 +0x5ea
github.com/petergtz/pegomock/pegomock/filehandling.GenerateMockFile(0xc000094c80, 0x2, 0x2, 0xc000074240, 0x52, 0x0, 0x0, 0xc000080642, 0x9, 0x0, ...)
/Users/pego/workspace/go/src/github.com/petergtz/pegomock/pegomock/filehandling/filehandling.go:64 +0xf0
github.com/petergtz/pegomock/pegomock/filehandling.GenerateMockFileInOutputDir(0xc000094c80, 0x2, 0x2, 0xc00001c004, 0x3d, 0x0, 0x0, 0x0, 0x0, 0xc000080642, ...)
/Users/pego/workspace/go/src/github.com/petergtz/pegomock/pegomock/filehandling/filehandling.go:40 +0x17f
main.Run(0xc000078060, 0x3, 0x3, 0x7e6f80, 0xc00008a000, 0x7e6f60, 0xc000084000, 0xc0000e8690, 0xc0000741e0)
/Users/pego/workspace/go/src/github.com/petergtz/pegomock/pegomock/main.go:116 +0x226e
main.main()
/Users/pego/workspace/go/src/github.com/petergtz/pegomock/pegomock/main.go:37 +0xa8
~/VisualStudioCode/go/<module>$ ls go.*
go.mod go.sum
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19 (12 by maintainers)
Commits related to this issue
- Add preliminary support for Modules https://github.com/petergtz/pegomock/issues/86 — committed to petergtz/pegomock by petergtz 5 years ago
- Fix logic to determine Go modules mode https://github.com/petergtz/pegomock/issues/86#issuecomment-493797705 — committed to petergtz/pegomock by petergtz 5 years ago
😄
Okay, will merge the changes into master and make a release. I’m sure there are still some cases which don’t properly work, but we can iterate on those.
Thanks again for reporting this and all the help troubleshooting it, @MrCreosote.
@MrCreosote I’ve just pushed another fix on
develop, that should follow the documentation as you’ve posted it above. With that change, you should be able to generate your mocks even without unsetting yourGOPATH. Would you mind trying it out one more time?@MrCreosote I gave it a first shot on the
developbranch. Please build thepegomockbinary from that branch and check if you’re able to generate your mock.@MrCreosote I could reproduce your problem and I found the root cause: Pegomock currently relies on
$GOPATHto be set. It’s not working with Go modules yet.Good news is: I’m almost done with a fix. Will post back with updates soon.
@MrCreosote OK, cool. Let me work with that and get back to you. I might need a couple of days, as this seems not trivial.