Add a test to validate the proposed fix

This commit is contained in:
erstam 2023-12-03 19:29:44 -05:00
parent c689108954
commit 86fcc67dd3
3 changed files with 27 additions and 3 deletions

View File

@ -32,7 +32,7 @@ var (
Fss = []Fs{&MemMapFs{}, &OsFs{}}
)
var testRegistry map[Fs][]string = make(map[Fs][]string)
var testRegistry = make(map[Fs][]string)
func testDir(fs Fs) string {
name, err := TempDir(fs, "", "afero")

View File

@ -59,8 +59,8 @@ func walk(fs Fs, path string, info os.FileInfo, walkFn filepath.WalkFunc) error
}
for _, name := range names {
if name == path {
// skip current directory to avoid infinite recursion
if name == "" {
// skip empty names to avoid infinite recursion
continue
}
filename := filepath.Join(path, name)

View File

@ -67,3 +67,27 @@ func TestWalk(t *testing.T) {
t.Fail()
}
}
func TestWalkRemoveRoot(t *testing.T) {
defer removeAllTestFiles(t)
fs := Fss[0]
rootPath := "."
err := fs.RemoveAll(rootPath)
if err != nil {
t.Error(err)
}
testRegistry[fs] = append(testRegistry[fs], rootPath)
setupTestFiles(t, fs, rootPath)
walkFn := func(path string, info os.FileInfo, err error) error {
fmt.Println(path, info.Name(), info.IsDir(), info.Size(), err)
return err
}
err = Walk(fs, rootPath, walkFn)
if err != nil {
t.Error(err)
}
}