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) {
t.Fatalf("Lstat %q succeeded after RemoveAll (second)", path)
}
// Make directory with file and subdirectory and trigger error.
if err = MkdirAll(dpath, 0777); err != nil {
t.Fatalf("MkdirAll %q: %s", dpath, err)
}
if Getuid() != 0 { // Test fails as root
// Make directory with file and subdirectory and trigger error.
if err = MkdirAll(dpath, 0777); err != nil {
t.Fatalf("MkdirAll %q: %s", dpath, err)
}
for _, s := range []string{fpath, dpath + "/file1", path + "/zzz"} {
fd, err = Open(s, O_WRONLY|O_CREAT, 0666);
if err != nil {
t.Fatalf("create %q: %s", s, err)
for _, s := range []string{fpath, dpath + "/file1", path + "/zzz"} {
fd, err = Open(s, O_WRONLY|O_CREAT, 0666);
if err != nil {
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 = RemoveAll(path); err == nil {
_, err := Lstat(path);
if err == nil {
t.Errorf("Can lstat %q after supposed RemoveAll", path)
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 == 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 {
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