Skip to content

Commit c7d6c60

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
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 <[email protected]> Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent 917171f commit c7d6c60

File tree

1 file changed

+47
-63
lines changed

1 file changed

+47
-63
lines changed

src/cmd/go/internal/modfetch/coderepo_test.go

+47-63
Original file line numberDiff line numberDiff line change
@@ -818,37 +818,29 @@ var codeRepoVersionsTests = []struct {
818818
func TestCodeRepoVersions(t *testing.T) {
819819
testenv.MustHaveExternalNetwork(t)
820820

821-
tmpdir, err := os.MkdirTemp("", "vgo-modfetch-test-")
822-
if err != nil {
823-
t.Fatal(err)
824-
}
825-
defer os.RemoveAll(tmpdir)
826-
827-
t.Run("parallel", func(t *testing.T) {
828-
for _, tt := range codeRepoVersionsTests {
829-
tt := tt
830-
t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) {
831-
if strings.Contains(tt.path, "gopkg.in") {
832-
testenv.SkipFlaky(t, 54503)
833-
}
821+
for _, tt := range codeRepoVersionsTests {
822+
tt := tt
823+
t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) {
824+
if strings.Contains(tt.path, "gopkg.in") {
825+
testenv.SkipFlaky(t, 54503)
826+
}
834827

835-
t.Parallel()
836-
if tt.vcs != "mod" {
837-
testenv.MustHaveExecPath(t, tt.vcs)
838-
}
839-
ctx := context.Background()
828+
t.Parallel()
829+
if tt.vcs != "mod" {
830+
testenv.MustHaveExecPath(t, tt.vcs)
831+
}
832+
ctx := context.Background()
840833

841-
repo := Lookup(ctx, "direct", tt.path)
842-
list, err := repo.Versions(ctx, tt.prefix)
843-
if err != nil {
844-
t.Fatalf("Versions(%q): %v", tt.prefix, err)
845-
}
846-
if !reflect.DeepEqual(list.List, tt.versions) {
847-
t.Fatalf("Versions(%q):\nhave %v\nwant %v", tt.prefix, list, tt.versions)
848-
}
849-
})
850-
}
851-
})
834+
repo := Lookup(ctx, "direct", tt.path)
835+
list, err := repo.Versions(ctx, tt.prefix)
836+
if err != nil {
837+
t.Fatalf("Versions(%q): %v", tt.prefix, err)
838+
}
839+
if !reflect.DeepEqual(list.List, tt.versions) {
840+
t.Fatalf("Versions(%q):\nhave %v\nwant %v", tt.prefix, list, tt.versions)
841+
}
842+
})
843+
}
852844
}
853845

854846
var latestTests = []struct {
@@ -897,43 +889,35 @@ var latestTests = []struct {
897889
func TestLatest(t *testing.T) {
898890
testenv.MustHaveExternalNetwork(t)
899891

900-
tmpdir, err := os.MkdirTemp("", "vgo-modfetch-test-")
901-
if err != nil {
902-
t.Fatal(err)
903-
}
904-
defer os.RemoveAll(tmpdir)
905-
906-
t.Run("parallel", func(t *testing.T) {
907-
for _, tt := range latestTests {
908-
name := strings.ReplaceAll(tt.path, "/", "_")
909-
t.Run(name, func(t *testing.T) {
910-
tt := tt
911-
t.Parallel()
912-
if tt.vcs != "mod" {
913-
testenv.MustHaveExecPath(t, tt.vcs)
914-
}
915-
ctx := context.Background()
892+
for _, tt := range latestTests {
893+
name := strings.ReplaceAll(tt.path, "/", "_")
894+
t.Run(name, func(t *testing.T) {
895+
tt := tt
896+
t.Parallel()
897+
if tt.vcs != "mod" {
898+
testenv.MustHaveExecPath(t, tt.vcs)
899+
}
900+
ctx := context.Background()
916901

917-
repo := Lookup(ctx, "direct", tt.path)
918-
info, err := repo.Latest(ctx)
919-
if err != nil {
920-
if tt.err != "" {
921-
if err.Error() == tt.err {
922-
return
923-
}
924-
t.Fatalf("Latest(): %v, want %q", err, tt.err)
925-
}
926-
t.Fatalf("Latest(): %v", err)
927-
}
902+
repo := Lookup(ctx, "direct", tt.path)
903+
info, err := repo.Latest(ctx)
904+
if err != nil {
928905
if tt.err != "" {
929-
t.Fatalf("Latest() = %v, want error %q", info.Version, tt.err)
930-
}
931-
if info.Version != tt.version {
932-
t.Fatalf("Latest() = %v, want %v", info.Version, tt.version)
906+
if err.Error() == tt.err {
907+
return
908+
}
909+
t.Fatalf("Latest(): %v, want %q", err, tt.err)
933910
}
934-
})
935-
}
936-
})
911+
t.Fatalf("Latest(): %v", err)
912+
}
913+
if tt.err != "" {
914+
t.Fatalf("Latest() = %v, want error %q", info.Version, tt.err)
915+
}
916+
if info.Version != tt.version {
917+
t.Fatalf("Latest() = %v, want %v", info.Version, tt.version)
918+
}
919+
})
920+
}
937921
}
938922

939923
// fixedTagsRepo is a fake codehost.Repo that returns a fixed list of tags

0 commit comments

Comments
 (0)