From 1f63aa0912705f6722873c8d4d1389c398f4d2df Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Thu, 23 Jan 2025 12:46:22 +0100 Subject: [PATCH] tests: Improve reporting in case of FS errors (#2216) ## Changes If there are unreadable files in a directory, raise an error but continue with further diagnostics, because the answer is in the script output. ## Tests Manually - I'm working on some tests that create unreadable files, the report is much better with this change. --- acceptance/acceptance_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 56db6ec20..96c1f651c 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -232,8 +232,7 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont } // Make sure there are not unaccounted for new files - files, err := ListDir(t, tmpDir) - require.NoError(t, err) + files := ListDir(t, tmpDir) for _, relPath := range files { if _, ok := inputs[relPath]; ok { continue @@ -450,11 +449,15 @@ func CopyDir(src, dst string, inputs, outputs map[string]bool) error { }) } -func ListDir(t *testing.T, src string) ([]string, error) { +func ListDir(t *testing.T, src string) []string { var files []string err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error { if err != nil { - return err + // Do not FailNow here. + // The output comparison is happening after this call which includes output.txt which + // includes errors printed by commands which include explanation why a given file cannot be read. + t.Errorf("Error when listing %s: path=%s: %s", src, path, err) + return nil } if info.IsDir() { @@ -469,5 +472,8 @@ func ListDir(t *testing.T, src string) ([]string, error) { files = append(files, relPath) return nil }) - return files, err + if err != nil { + t.Errorf("Failed to list %s: %s", src, err) + } + return files }