Skip to content

Commit 5845b37

Browse files
toothrotgopherbot
authored andcommitted
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 <[email protected]> Auto-Submit: Jenny Rakoczy <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Jenny Rakoczy <[email protected]>
1 parent 12c20b8 commit 5845b37

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

internal/relui/buildrelease_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func serveTarball(pathMatch string, files map[string]string, w http.ResponseWrit
466466
}
467467
}
468468

469-
func checkFile(t *testing.T, dlURL string, files map[string]*WebsiteFile, filename string, meta *WebsiteFile, check func([]byte)) {
469+
func checkFile(t *testing.T, dlURL string, files map[string]*WebsiteFile, filename string, meta *WebsiteFile, check func(*testing.T, []byte)) {
470470
t.Run(filename, func(t *testing.T) {
471471
f, ok := files[filename]
472472
if !ok {
@@ -483,20 +483,20 @@ func checkFile(t *testing.T, dlURL string, files map[string]*WebsiteFile, filena
483483
if err != nil {
484484
t.Fatalf("reading %v: %v", f.Filename, err)
485485
}
486-
check(body)
486+
check(t, body)
487487
})
488488
}
489489

490490
func checkContents(t *testing.T, dlURL string, files map[string]*WebsiteFile, filename string, meta *WebsiteFile, contents string) {
491-
checkFile(t, dlURL, files, filename, meta, func(b []byte) {
491+
checkFile(t, dlURL, files, filename, meta, func(t *testing.T, b []byte) {
492492
if got, want := string(b), contents; got != want {
493493
t.Errorf("%v contains %q, want %q", filename, got, want)
494494
}
495495
})
496496
}
497497

498498
func checkTGZ(t *testing.T, dlURL string, files map[string]*WebsiteFile, filename string, meta *WebsiteFile, contents map[string]string) {
499-
checkFile(t, dlURL, files, filename, meta, func(b []byte) {
499+
checkFile(t, dlURL, files, filename, meta, func(t *testing.T, b []byte) {
500500
gzr, err := gzip.NewReader(bytes.NewReader(b))
501501
if err != nil {
502502
t.Fatal(err)
@@ -530,7 +530,7 @@ func checkTGZ(t *testing.T, dlURL string, files map[string]*WebsiteFile, filenam
530530
}
531531

532532
func checkZip(t *testing.T, dlURL string, files map[string]*WebsiteFile, filename string, meta *WebsiteFile, contents map[string]string) {
533-
checkFile(t, dlURL, files, filename, meta, func(b []byte) {
533+
checkFile(t, dlURL, files, filename, meta, func(t *testing.T, b []byte) {
534534
zr, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
535535
if err != nil {
536536
t.Fatal(err)

0 commit comments

Comments
 (0)