File: mod_go122_test.go

package info (click to toggle)
golang-golang-x-tools 1%3A0.25.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 22,724 kB
  • sloc: javascript: 2,027; asm: 1,645; sh: 166; yacc: 155; makefile: 49; ansic: 8
file content (58 lines) | stat: -rw-r--r-- 1,221 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.22
// +build go1.22

package imports

import (
	"context"
	"testing"
)

// Tests that go.work files and vendor directory are respected.
func TestModWorkspaceVendoring(t *testing.T) {
	mt := setup(t, nil, `
-- go.work --
go 1.22

use (
	./a
	./b
)
-- a/go.mod --
module example.com/a

go 1.22

require rsc.io/sampler v1.3.1
-- a/a.go --
package a

import _ "rsc.io/sampler"
-- b/go.mod --
module example.com/b

go 1.22
-- b/b.go --
package b
`, "")
	defer mt.cleanup()

	// generate vendor directory
	if _, err := mt.env.invokeGo(context.Background(), "work", "vendor"); err != nil {
		t.Fatal(err)
	}

	// update module resolver
	mt.env.ClearModuleInfo()
	mt.env.UpdateResolver(mt.env.resolver.ClearForNewScan())

	mt.assertModuleFoundInDir("example.com/a", "a", `main/a$`)
	mt.assertScanFinds("example.com/a", "a")
	mt.assertModuleFoundInDir("example.com/b", "b", `main/b$`)
	mt.assertScanFinds("example.com/b", "b")
	mt.assertModuleFoundInDir("rsc.io/sampler", "sampler", `/vendor/`)
}