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

Potential import collision: import path should be "gopkg.in/h2non/gock.v1", not "github.com/h2non/gock". #69

Open
KateGo520 opened this issue Aug 11, 2020 · 4 comments

Comments

@KateGo520
Copy link

Background

The h2non/gock has already renamed it’s import path from "github.com/h2non/gock" to "gopkg.in/h2non/gock.v1".
As README of h2non/gock v1.0.9 said, downstream repos should use "gopkg.in/h2non/gock.v1" to get or import h2non/gock.

**Installation**
> go get -u gopkg.in/h2non/gock.v1

**Examples**
See examples directory for more featured use cases.
Simple mocking via tests
package test
import (
  "github.com/nbio/st"
  "gopkg.in/h2non/gock.v1"
  "io/ioutil"
  "net/http"
  "testing"
)
…

But drone/go-scm still used the old path:
https://github.com/drone/go-scm/blob/master/go.mod#L5

github.com/h2non/gock v1.0.9

When you use the old path "github.com/h2non/gock" to import the h2non/gock, it will be very easy to reintroduce h2non/gock through the import statements "import gopkg.in/h2non/gock.v1" in the go source file of h2non/gock`.
https://github.com/h2non/gock/blob/v1.0.9/_examples/custom_matcher/matcher.go#L5

package main
import (
	"fmt"
	"gopkg.in/h2non/gock.v1"
	"net/http"
)
…

The "gopkg.in/h2non/gock.v1" and "github.com/h2non/gock" are the same repos. This will work in isolation, bring about potential risks and problems.

So, why not get rid of the old import path "github.com/h2non/gock ", use "gopkg.in/h2non/gock.v1" instead.

Solution

Replace all the old import paths, change "github.com/h2non/gock" to "gopkg.in/h2non/gock.v1".
Where did you import it: https://github.com/drone/go-scm/search?q=github.com%2Fh2non%2Fgock&unscoped_q=github.com%2Fh2non%2Fgock

@KateGo520
Copy link
Author

@bradrydzewski @chhsia0 Could you help me review this issue? Thx :p

@tboerger
Copy link
Contributor

Gock is not using any imports for itself, so both imports are working. This library doesn't really need the old gopkg.in behavior because of Go modules. So I don't see a big need to change that now.

@bradrydzewski
Copy link
Member

@tboerger it looks like the go.mod file uses gopkg.in/h2non/gock.v1 as the module name so we may need to change the import. Very strange they are using gopkg with go.mod but not much we can do about that.

@KateGo520
Copy link
Author

Thank you for your reply! @tboerger @bradrydzewski
Yes, github.com/h2non/gock declared it's module path as "gopkg.in/h2non/gock.v1" in go.mod. Continuing to use the import path "github.com/h2non/gock" may be more problematic.
https://github.com/h2non/gock/blob/master/go.mod#L1

module gopkg.in/h2non/gock.v1

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

3 participants