]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modfetch: avoid creating unused temp directories
authorBryan C. Mills <bcmills@google.com>
Thu, 11 May 2023 14:37:44 +0000 (10:37 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 18 May 2023 20:10:14 +0000 (20:10 +0000)
(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>
src/cmd/go/internal/modfetch/coderepo_test.go

index cf9c93d1fdc3cbb472b1675cf1f83ce3f6bbdff0..aad78722c09c6a61068a8dc55da5ba251f61e1f3 100644 (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)
-       }
-       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)
-                               }
+       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()
+                       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)
-                               }
-                       })
-               }
-       })
+                       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)
-
-       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()
+       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 info.Version != tt.version {
-                                       t.Fatalf("Latest() = %v, want %v", info.Version, tt.version)
+                                       if err.Error() == tt.err {
+                                               return
+                                       }
+                                       t.Fatalf("Latest(): %v, want %q", err, tt.err)
                                }
-                       })
-               }
-       })
+                               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