1
0
mirror of https://github.com/golang/go synced 2024-11-22 07:24:47 -07:00

os: fix test of RemoveAll

Fixes #22. (again)

R=r
CC=golang-dev
https://golang.org/cl/3547041
This commit is contained in:
Russ Cox 2010-12-09 14:49:13 -05:00
parent 6555cfc6c6
commit 92b4506f73

View File

@ -130,23 +130,17 @@ func TestRemoveAll(t *testing.T) {
if err = Chmod(dpath, 0); err != nil { if err = Chmod(dpath, 0); err != nil {
t.Fatalf("Chmod %q 0: %s", dpath, err) t.Fatalf("Chmod %q 0: %s", dpath, err)
} }
if err = RemoveAll(path); err == nil {
_, err := Lstat(path) // No error checking here: either RemoveAll
if err == nil { // will or won't be able to remove dpath;
t.Errorf("Can lstat %q after supposed RemoveAll", path) // either way we want to see if it removes fpath
} // and path/zzz. Reasons why RemoveAll might
t.Fatalf("RemoveAll %q succeeded with chmod 0 subdirectory: err %s", path, err) // succeed in removing dpath as well include:
} // * running as root
perr, ok := err.(*PathError) // * running on a file system without permissions (FAT)
if !ok { RemoveAll(path)
t.Fatalf("RemoveAll %q returned %T not *PathError", path, err) Chmod(dpath, 0777)
}
if perr.Path != dpath {
t.Fatalf("RemoveAll %q failed at %q not %q", path, perr.Path, dpath)
}
if err = Chmod(dpath, 0777); err != nil {
t.Fatalf("Chmod %q 0777: %s", dpath, err)
}
for _, s := range []string{fpath, path + "/zzz"} { for _, s := range []string{fpath, path + "/zzz"} {
if _, err := Lstat(s); err == nil { if _, err := Lstat(s); err == nil {
t.Fatalf("Lstat %q succeeded after partial RemoveAll", s) t.Fatalf("Lstat %q succeeded after partial RemoveAll", s)