mirror of https://github.com/spf13/afero.git
Add a test to validate the proposed fix
This commit is contained in:
parent
c689108954
commit
86fcc67dd3
|
@ -32,7 +32,7 @@ var (
|
||||||
Fss = []Fs{&MemMapFs{}, &OsFs{}}
|
Fss = []Fs{&MemMapFs{}, &OsFs{}}
|
||||||
)
|
)
|
||||||
|
|
||||||
var testRegistry map[Fs][]string = make(map[Fs][]string)
|
var testRegistry = make(map[Fs][]string)
|
||||||
|
|
||||||
func testDir(fs Fs) string {
|
func testDir(fs Fs) string {
|
||||||
name, err := TempDir(fs, "", "afero")
|
name, err := TempDir(fs, "", "afero")
|
||||||
|
|
4
path.go
4
path.go
|
@ -59,8 +59,8 @@ func walk(fs Fs, path string, info os.FileInfo, walkFn filepath.WalkFunc) error
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
if name == path {
|
if name == "" {
|
||||||
// skip current directory to avoid infinite recursion
|
// skip empty names to avoid infinite recursion
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
filename := filepath.Join(path, name)
|
filename := filepath.Join(path, name)
|
||||||
|
|
24
path_test.go
24
path_test.go
|
@ -67,3 +67,27 @@ func TestWalk(t *testing.T) {
|
||||||
t.Fail()
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue