Commit 1971e1bd authored by Russ Cox's avatar Russ Cox

os: do not test error case of TestRemoveAll when root

Fixes #22.

R=r1, r
https://golang.org/cl/152073
parent 364e564e
...@@ -104,35 +104,38 @@ func TestRemoveAll(t *testing.T) { ...@@ -104,35 +104,38 @@ func TestRemoveAll(t *testing.T) {
t.Fatalf("Lstat %q succeeded after RemoveAll (second)", path) t.Fatalf("Lstat %q succeeded after RemoveAll (second)", path)
} }
// Make directory with file and subdirectory and trigger error. if Getuid() != 0 { // Test fails as root
if err = MkdirAll(dpath, 0777); err != nil { // Make directory with file and subdirectory and trigger error.
t.Fatalf("MkdirAll %q: %s", dpath, err) if err = MkdirAll(dpath, 0777); err != nil {
} t.Fatalf("MkdirAll %q: %s", dpath, err)
}
for _, s := range []string{fpath, dpath + "/file1", path + "/zzz"} { for _, s := range []string{fpath, dpath + "/file1", path + "/zzz"} {
fd, err = Open(s, O_WRONLY|O_CREAT, 0666); fd, err = Open(s, O_WRONLY|O_CREAT, 0666);
if err != nil { if err != nil {
t.Fatalf("create %q: %s", s, err) t.Fatalf("create %q: %s", s, err)
}
fd.Close();
} }
fd.Close(); if err = Chmod(dpath, 0); err != nil {
} t.Fatalf("Chmod %q 0: %s", dpath, err)
if err = Chmod(dpath, 0); err != nil { }
t.Fatalf("Chmod %q 0: %s", dpath, err) if err = RemoveAll(path); err == nil {
} _, err := Lstat(path);
if err = RemoveAll(path); err == nil { if err == nil {
_, err := Lstat(path); t.Errorf("Can lstat %q after supposed RemoveAll", path)
if err == nil { }
t.Errorf("Can lstat %q after supposed RemoveAll", path) t.Fatalf("RemoveAll %q succeeded with chmod 0 subdirectory", path, err);
}
perr, ok := err.(*PathError);
if !ok {
t.Fatalf("RemoveAll %q returned %T not *PathError", path, err)
}
if perr.Path != dpath {
t.Fatalf("RemoveAll %q failed at %q not %q", path, perr.Path, dpath)
} }
t.Fatalf("RemoveAll %q succeeded with chmod 0 subdirectory", path, err);
}
perr, ok := err.(*PathError);
if !ok {
t.Fatalf("RemoveAll %q returned %T not *PathError", path, err)
}
if perr.Path != dpath {
t.Fatalf("RemoveAll %q failed at %q not %q", path, perr.Path, dpath)
} }
if err = Chmod(dpath, 0777); err != nil { if err = Chmod(dpath, 0777); err != nil {
t.Fatalf("Chmod %q 0777: %s", dpath, err) t.Fatalf("Chmod %q 0777: %s", dpath, err)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment