Skip to content

cmd/go: in tests, populate go.sum files and reduce usage of -mod=mod #41302

Open
@jayconrod

Description

@jayconrod

This issue acts as a TODO for a number of comments raised in review of CL 251881, which enables -mod=readonly by default for #40278. Two broad issues should be fixed in the cmd/go integration tests.

First, -mod=mod is used in a lot of places with go list or go build. We should make the tests follow more idiomatic usage. If something is missing from go.mod or go.sum, we should run go get -d, go mod tidy, or go mod download first. The following tests need changes. There are probably more.

  • mod_doc
  • mod_download.
  • mod_invalid_version
  • mod_list
  • mod_load_badzip
  • mod_replace
  • mod_replace_gopkgin
  • mod_require_exclude
  • mod_sumdb_golang

Second, many tests fail without -mod=mod because the test archive doesn't include a go.sum file. I'd rather not include literal go.sum files in tests, since they'll make tests more difficult to write and act as change detectors. Instead, we should have a command or sequence of commands run at the beginning of a test that fills in missing sums without modifying go.mod. Something like:

cp go.mod go.mod.orig
go get -d ./...
cmp go.mod go.mod.orig

If this turns out to be too repetitive, we may want to add a script_test.go command to shorten it.

The following tests need changes. Again, there are probably more.

  • mod_list_dir
  • mod_list_replace_dir
  • mod_list_upgrade
  • mod_load_badmod
  • mod_modinfo

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsFixThe path to resolution is known, but the work has not been done.TestingAn issue that has been verified to require only test changes, not just a test failure.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions