Skip to content

Commit

Permalink
tests: Improve reporting in case of FS errors (#2216)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
denik authored Jan 23, 2025
1 parent 798189e commit 1f63aa0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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
}

0 comments on commit 1f63aa0

Please sign in to comment.