Skip to content

Commit

Permalink
internal/relui: use correct testing.T in checkFile
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
toothrot authored and gopherbot committed Aug 15, 2022
1 parent 12c20b8 commit 5845b37
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/relui/buildrelease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -483,20 +483,20 @@ 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)
}
})
}

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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5845b37

Please sign in to comment.