From 5845b3714afbe70a1c7417d5c3d423303aa4a536 Mon Sep 17 00:00:00 2001 From: Alex Rakoczy Date: Mon, 15 Aug 2022 11:17:54 -0400 Subject: [PATCH] internal/relui: use correct testing.T in checkFile checkFile starts its own subtest, accepting a function for validating the file contents. If there is a mismatch in the file, the check function has the parent's testing.T instead of the correct one for the subtest. This should resolve the flake on "test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test" For golang/go#53972 Change-Id: I62d9b2e596cd87f925338ba4d997684cb438d784 Reviewed-on: https://go-review.googlesource.com/c/build/+/423914 Reviewed-by: Heschi Kreinick Auto-Submit: Jenny Rakoczy TryBot-Result: Gopher Robot Run-TryBot: Jenny Rakoczy --- internal/relui/buildrelease_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/relui/buildrelease_test.go b/internal/relui/buildrelease_test.go index 5a78fa0813..a599188935 100644 --- a/internal/relui/buildrelease_test.go +++ b/internal/relui/buildrelease_test.go @@ -466,7 +466,7 @@ func serveTarball(pathMatch string, files map[string]string, w http.ResponseWrit } } -func checkFile(t *testing.T, dlURL string, files map[string]*WebsiteFile, filename string, meta *WebsiteFile, check func([]byte)) { +func checkFile(t *testing.T, dlURL string, files map[string]*WebsiteFile, filename string, meta *WebsiteFile, check func(*testing.T, []byte)) { t.Run(filename, func(t *testing.T) { f, ok := files[filename] if !ok { @@ -483,12 +483,12 @@ func checkFile(t *testing.T, dlURL string, files map[string]*WebsiteFile, filena if err != nil { t.Fatalf("reading %v: %v", f.Filename, err) } - check(body) + check(t, body) }) } func checkContents(t *testing.T, dlURL string, files map[string]*WebsiteFile, filename string, meta *WebsiteFile, contents string) { - checkFile(t, dlURL, files, filename, meta, func(b []byte) { + checkFile(t, dlURL, files, filename, meta, func(t *testing.T, b []byte) { if got, want := string(b), contents; got != want { t.Errorf("%v contains %q, want %q", filename, got, want) } @@ -496,7 +496,7 @@ func checkContents(t *testing.T, dlURL string, files map[string]*WebsiteFile, fi } func checkTGZ(t *testing.T, dlURL string, files map[string]*WebsiteFile, filename string, meta *WebsiteFile, contents map[string]string) { - checkFile(t, dlURL, files, filename, meta, func(b []byte) { + checkFile(t, dlURL, files, filename, meta, func(t *testing.T, b []byte) { gzr, err := gzip.NewReader(bytes.NewReader(b)) if err != nil { t.Fatal(err) @@ -530,7 +530,7 @@ func checkTGZ(t *testing.T, dlURL string, files map[string]*WebsiteFile, filenam } func checkZip(t *testing.T, dlURL string, files map[string]*WebsiteFile, filename string, meta *WebsiteFile, contents map[string]string) { - checkFile(t, dlURL, files, filename, meta, func(b []byte) { + checkFile(t, dlURL, files, filename, meta, func(t *testing.T, b []byte) { zr, err := zip.NewReader(bytes.NewReader(b), int64(len(b))) if err != nil { t.Fatal(err)