go/packages: remove go.mod files

Files named go.mod define a module boundary and punch a hole in the
repository when the module is fetched with go get. We had a couple in
testdata. Get rid of them.

In one case the changes I made to produce a module cache in packagestest
were enough. In the other, the test needs multiple minor/patch versions
of the same module, which we have no provision for. Rename them to
"definitelynot_go.mod" in the repo and fix it up in the test.

Updates golang/go#34352

Change-Id: I284578b3aebb0f1fec3ddb4bef0df24f050d0636
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196258
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Heschi Kreinick 2019-09-18 15:07:38 -04:00
parent 9098376d50
commit 68f92b6635
19 changed files with 23 additions and 44 deletions

View File

@ -1543,41 +1543,37 @@ func testName(t *testing.T, exporter packagestest.Exporter) {
func TestName_Modules(t *testing.T) { func TestName_Modules(t *testing.T) {
// Test the top-level package case described in runNamedQueries. // Test the top-level package case described in runNamedQueries.
// Note that overriding GOPATH below prevents Export from exported := packagestest.Export(t, packagestest.Modules, []packagestest.Module{
// creating more than one module. {
exported := packagestest.Export(t, packagestest.Modules, []packagestest.Module{{ Name: "golang.org/pkg",
Name: "golang.org/pkg", Files: map[string]interface{}{
Files: map[string]interface{}{ "pkg.go": `package pkg`,
"pkg.go": `package pkg`, },
}}}) },
{
Name: "example.com/tools-testrepo",
Files: map[string]interface{}{
"pkg/pkg.go": `package pkg`,
},
},
{
Name: "example.com/tools-testrepo/v2",
Files: map[string]interface{}{
"pkg/pkg.go": `package pkg`,
},
},
})
defer exported.Cleanup() defer exported.Cleanup()
wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
gopath, err := ioutil.TempDir("", "TestName_Modules")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(gopath)
if err := copyAll(filepath.Join(wd, "testdata", "TestName_Modules"), gopath); err != nil {
t.Fatal(err)
}
// testdata/TestNamed_Modules contains:
// - pkg/mod/github.com/heschik/tools-testrepo@v1.0.0/pkg
// - pkg/mod/github.com/heschik/tools-testrepo/v2@v2.0.0/pkg
// - src/b/pkg
exported.Config.Mode = packages.LoadImports exported.Config.Mode = packages.LoadImports
exported.Config.Env = append(exported.Config.Env, "GOPATH="+gopath)
initial, err := packages.Load(exported.Config, "iamashamedtousethedisabledqueryname=pkg") initial, err := packages.Load(exported.Config, "iamashamedtousethedisabledqueryname=pkg")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
graph, _ := importGraph(initial) graph, _ := importGraph(initial)
wantGraph := ` wantGraph := `
* github.com/heschik/tools-testrepo/pkg * example.com/tools-testrepo/pkg
* github.com/heschik/tools-testrepo/v2/pkg * example.com/tools-testrepo/v2/pkg
* golang.org/pkg * golang.org/pkg
`[1:] `[1:]
if graph != wantGraph { if graph != wantGraph {
@ -2504,7 +2500,7 @@ func copyAll(srcPath, dstPath string) error {
if err != nil { if err != nil {
return err return err
} }
dstFilePath := filepath.Join(dstPath, rel) dstFilePath := strings.Replace(filepath.Join(dstPath, rel), "definitelynot_go.mod", "go.mod", -1)
if err := os.MkdirAll(filepath.Dir(dstFilePath), 0755); err != nil { if err := os.MkdirAll(filepath.Dir(dstFilePath), 0755); err != nil {
return err return err
} }

View File

@ -1 +0,0 @@
{"Version":"v1.0.0","Time":"2018-09-28T22:09:08Z"}

View File

@ -1 +0,0 @@
module github.com/heschik/tools-testrepo

View File

@ -1 +0,0 @@
h1:D2qc+R2eCTCyoT8WAYoExXhPBThJWmlYSfB4coWbfBE=

View File

@ -1 +0,0 @@
{"Version":"v2.0.0","Time":"2018-09-28T22:12:08Z"}

View File

@ -1 +0,0 @@
module github.com/heschik/tools-testrepo/v2

View File

@ -1 +0,0 @@
h1:Ll4Bx8ZD8zg8lD4idX7CAhx/jh16o9dWC2m9SnT1qu0=

View File

@ -1 +0,0 @@
package pkg

View File

@ -1,3 +0,0 @@
module github.com/heschik/tools-testrepo/v2
go 1.12

View File

@ -1,3 +0,0 @@
module github.com/heschik/tools-testrepo
go 1.12