golang.org/x/tools@v0.21.0/internal/imports/mod_go122_test.go (about) 1 // Copyright 2019 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build go1.22 6 // +build go1.22 7 8 package imports 9 10 import ( 11 "context" 12 "testing" 13 ) 14 15 // Tests that go.work files and vendor directory are respected. 16 func TestModWorkspaceVendoring(t *testing.T) { 17 mt := setup(t, nil, ` 18 -- go.work -- 19 go 1.22 20 21 use ( 22 ./a 23 ./b 24 ) 25 -- a/go.mod -- 26 module example.com/a 27 28 go 1.22 29 30 require rsc.io/sampler v1.3.1 31 -- a/a.go -- 32 package a 33 34 import _ "rsc.io/sampler" 35 -- b/go.mod -- 36 module example.com/b 37 38 go 1.22 39 -- b/b.go -- 40 package b 41 `, "") 42 defer mt.cleanup() 43 44 // generate vendor directory 45 if _, err := mt.env.invokeGo(context.Background(), "work", "vendor"); err != nil { 46 t.Fatal(err) 47 } 48 49 // update module resolver 50 mt.env.ClearModuleInfo() 51 mt.env.UpdateResolver(mt.env.resolver.ClearForNewScan()) 52 53 mt.assertModuleFoundInDir("example.com/a", "a", `main/a$`) 54 mt.assertScanFinds("example.com/a", "a") 55 mt.assertModuleFoundInDir("example.com/b", "b", `main/b$`) 56 mt.assertScanFinds("example.com/b", "b") 57 mt.assertModuleFoundInDir("rsc.io/sampler", "sampler", `/vendor/`) 58 }