h2non / gock

HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽

Home Page:https://pkg.go.dev/github.com/h2non/gock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go mod vendor: parsing go.mod: unexpected module path "gopkg.in/h2non/gock.v1"

prologic opened this issue · comments

I run into an error trying to run go mod vendor (we sadly are using Go11Modules + Vendoring at the moment):

$ go mod vendor
go: github.com/h2non/gock@v1.0.14: parsing go.mod: unexpected module path "gopkg.in/h2non/gock.v1"
go: error loading module requirements

Any ideas why go mod is complaining here?

It seems to me that your module def in go.mod is what go mod doesn't like:

$ GOPROXY="" go get -u github.com/h2non/gock
go: github.com/h2non/gock@v1.0.14: parsing go.mod: unexpected module path "gopkg.in/h2non/gock.v1"
go get: error loading module requirements

The work-around here is to use a replace in my go.mod:

$ git diff go.mod
diff --git a/go.mod b/go.mod
index 5b494df..67fad48 100644
--- a/go.mod
+++ b/go.mod
@@ -8,6 +8,7 @@ require (
        github.com/gogo/protobuf v1.2.0 // indirect
        github.com/google/uuid v1.1.0 // indirect
        github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 // indirect
+       github.com/h2non/gock v0.0.0-00010101000000-000000000000
        github.com/improbable-eng/go-httpwares v0.0.0-20190118142334-33c6690a604c
        github.com/inconshreveable/mousetrap v1.0.0 // indirect
        github.com/kataras/muxie v1.0.7
@@ -23,6 +24,9 @@ require (
        golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
        golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06 // indirect
        google.golang.org/grpc v1.17.0 // indirect
+       gopkg.in/h2non/gock.v1 v1.0.14 // indirect
        gopkg.in/src-d/go-git.v4 v4.9.1
        gopkg.in/yaml.v2 v2.2.2
 )
+
+replace github.com/h2non/gock => gopkg.in/h2non/gock.v1 v1.0.14

I found a similar work-around by searching around. Example: go-resty/resty#230

From doing some grep'ing around your codebase; it looks like you mix github.com/ and gopokg.in/ import paths for your own package -- I believe this is confusing go mod utterly. Can you fix this? :)

Seconding the request to have this fixed. :)

Thanks for the workaround, @prologic.

This is because github.com/h2non/gock is supposed to be imported as gopkg.in/h2non/gock.v1, according to its go.mod file. When go mod downloads the module, it checks whether the module declaration matches the import path. The replace statement is just a workaround. You should change the imports and go get command