-3

I have a fork of someone's code. Their module name is formatted like so:

module github.com/foo/bar/v3

I've made some changes locally and have updated the local go.mod to be v4 instead of v3 but this now causes the running of the tests locally to fail (see below, I've genericized the output).

Note: the go.sum at this point is empty.

$ go test -v

go: finding module for package github.com/foo/bar/v3
go: found github.com/foo/bar/v3 in github.com/foo/bar/v3 v3.0.0
# github.com/foo/bar/v4_test [github.com/foo/bar/v4.test]
./some_test.go:232:19: x.Y undefined (type *package.Example has no field or method Y)
FAIL    github.com/foo/bar/v4 [build failed]

I'm not sure why it's trying to locate the actual v3 version of the package, and thus updating the go.sum to include it?

I can see from the test file that this package uses a different package name (e.g. package foo_test) so it doesn't rely on the exported data structures to exist when writing their test code. So maybe that's why this happens? it sees the reference to x.Y and then goes to lookup x in github.

But then I'm not sure why the test would run fine when I was using the v3 reference in the go.mod file?

Any ideas on what's happening here and what the right process should be for bumping a go module when you're working on a forked project?

Thanks.

Integralist
  • 5,899
  • 5
  • 25
  • 42
  • 3
    You changed the module name, did you change all the relevant import statements as well? – JimB Sep 16 '20 at 11:10
  • @JimB OMG! What a bell end I've been ‍♂️ What makes this worse is that I literally was reading this in the go blog the other day when refreshing my memory on go module versioning. Thank you! – Integralist Sep 16 '20 at 15:42

1 Answers1

4

If you change your module name in go.mod file, you have to replace all your import path with the updated module name.

As you replaced your module github.com/foo/bar/v3 with github.com/foo/bar/v4, you must find and replace all your reference of github.com/foo/bar/v3 with github.com/foo/bar/v4 throughout the whole project.

Then your $ go test -v should run properly.

Masudur Rahman
  • 1,585
  • 8
  • 16