godog
godog copied to clipboard
Failed after go mod vendor
What version of godog are you using?
v0.11.0
What version of Go are you using?
> go version
go version go1.16.5 darwin/amd64
What did you do?
Followed the example in directory godogs2, by default godog runs fine with go mod.
But after vendor is used, it fails by default.
➜ godogs2 go get github.com/cucumber/godog
go get: added github.com/cucumber/godog v0.11.0
➜ godogs2 godog
No scenarios
No steps
16.315µs
➜ godogs2 go mod vendor
go: warning: "all" matched no packages
➜ godogs2 tree
.
├── go.mod
├── go.sum
└── vendor
└── modules.txt
1 directory, 3 files
What did you expect to see?
Same result as before go mod vendor
➜ godogs2 godog
No scenarios
No steps
16.315µs
What did you see instead?
failed to compile tested package: /Users/whuang/code/go/godogs2, reason: exit status 1, output: WORK=/var/folders/sl/9zn0ht317s52y6vyqtc3gt6m0000gn/T/go-build3552059817
# godogs
godog_dependency_file_test.go:3:8: cannot find package "." in:
/Users/whuang/code/go/godogs2/vendor/github.com/cucumber/godog
FAIL godogs [setup failed]
Additional context
You're now using vendored packages, which in theory if don't have any reference to godog in any .go code, it won't be included in the /vendor folder, it will be listed in vendor/modules.txt but as a comment. You can check that the package doesn't exist in the /vendor folder.
To fix it you need to use godog in any go file and run go mod vendor again, godog should be included in /vendor and the godog command should work :)
Thanks @rwngallego-lm for the explanation. Is there a way to force downloading godog in /vendor folder? In an existing go project that uses vendor and doesn't need godog code in project, how can I simply use godog as a cli tool to run feature files?
Eventually you will end up having a reference to godog when you create the _test.go files that accompany the feature files, however if you're following the example that shows the suggested go code implementation in an existing project with no godog references yet, it will not work unless you add a dummy reference. Once you have the first _test.go godog implementation, you should not have any issues generating the rest of the go files out from the feature files.
Makes sense! And since in non-vendor case, even if there's no godog reference, godog gives proper output. Can it give the same friendly output as below in vendor case (even though no godog reference)?
➜ godogs2 godog
No scenarios
No steps
16.315µs
@davix have you tried to run:
go mod tidy
go mod vendor