1
0
mirror of https://github.com/golang/go synced 2024-11-23 07:50:05 -07:00

cmd/go/internal/modfetch: avoid creating unused temp directories

(Discovered via #60113, but this doesn't address that issue.)

Change-Id: I8b89e74b786dcfb0aa5d71fcbd0df8af33b98f36
Reviewed-on: https://go-review.googlesource.com/c/go/+/494375
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Bryan C. Mills 2023-05-11 10:37:44 -04:00 committed by Gopher Robot
parent 917171f564
commit c7d6c6000a

View File

@ -818,37 +818,29 @@ var codeRepoVersionsTests = []struct {
func TestCodeRepoVersions(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
tmpdir, err := os.MkdirTemp("", "vgo-modfetch-test-")
if err != nil {
t.Fatal(err)
for _, tt := range codeRepoVersionsTests {
tt := tt
t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) {
if strings.Contains(tt.path, "gopkg.in") {
testenv.SkipFlaky(t, 54503)
}
t.Parallel()
if tt.vcs != "mod" {
testenv.MustHaveExecPath(t, tt.vcs)
}
ctx := context.Background()
repo := Lookup(ctx, "direct", tt.path)
list, err := repo.Versions(ctx, tt.prefix)
if err != nil {
t.Fatalf("Versions(%q): %v", tt.prefix, err)
}
if !reflect.DeepEqual(list.List, tt.versions) {
t.Fatalf("Versions(%q):\nhave %v\nwant %v", tt.prefix, list, tt.versions)
}
})
}
defer os.RemoveAll(tmpdir)
t.Run("parallel", func(t *testing.T) {
for _, tt := range codeRepoVersionsTests {
tt := tt
t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) {
if strings.Contains(tt.path, "gopkg.in") {
testenv.SkipFlaky(t, 54503)
}
t.Parallel()
if tt.vcs != "mod" {
testenv.MustHaveExecPath(t, tt.vcs)
}
ctx := context.Background()
repo := Lookup(ctx, "direct", tt.path)
list, err := repo.Versions(ctx, tt.prefix)
if err != nil {
t.Fatalf("Versions(%q): %v", tt.prefix, err)
}
if !reflect.DeepEqual(list.List, tt.versions) {
t.Fatalf("Versions(%q):\nhave %v\nwant %v", tt.prefix, list, tt.versions)
}
})
}
})
}
var latestTests = []struct {
@ -897,43 +889,35 @@ var latestTests = []struct {
func TestLatest(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
tmpdir, err := os.MkdirTemp("", "vgo-modfetch-test-")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
for _, tt := range latestTests {
name := strings.ReplaceAll(tt.path, "/", "_")
t.Run(name, func(t *testing.T) {
tt := tt
t.Parallel()
if tt.vcs != "mod" {
testenv.MustHaveExecPath(t, tt.vcs)
}
ctx := context.Background()
t.Run("parallel", func(t *testing.T) {
for _, tt := range latestTests {
name := strings.ReplaceAll(tt.path, "/", "_")
t.Run(name, func(t *testing.T) {
tt := tt
t.Parallel()
if tt.vcs != "mod" {
testenv.MustHaveExecPath(t, tt.vcs)
}
ctx := context.Background()
repo := Lookup(ctx, "direct", tt.path)
info, err := repo.Latest(ctx)
if err != nil {
if tt.err != "" {
if err.Error() == tt.err {
return
}
t.Fatalf("Latest(): %v, want %q", err, tt.err)
}
t.Fatalf("Latest(): %v", err)
}
repo := Lookup(ctx, "direct", tt.path)
info, err := repo.Latest(ctx)
if err != nil {
if tt.err != "" {
t.Fatalf("Latest() = %v, want error %q", info.Version, tt.err)
if err.Error() == tt.err {
return
}
t.Fatalf("Latest(): %v, want %q", err, tt.err)
}
if info.Version != tt.version {
t.Fatalf("Latest() = %v, want %v", info.Version, tt.version)
}
})
}
})
t.Fatalf("Latest(): %v", err)
}
if tt.err != "" {
t.Fatalf("Latest() = %v, want error %q", info.Version, tt.err)
}
if info.Version != tt.version {
t.Fatalf("Latest() = %v, want %v", info.Version, tt.version)
}
})
}
}
// fixedTagsRepo is a fake codehost.Repo that returns a fixed list of tags