summaryrefslogtreecommitdiff
path: root/src/pkg/os
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-11-11 12:00:34 -0800
committerRuss Cox <rsc@golang.org>2009-11-11 12:00:34 -0800
commit9da9a1e02f7eda25def1c6fa807054493209e413 (patch)
tree8a254ccfaaf0e4ab6ca84ef76a0b8b0419cc8a04 /src/pkg/os
parent0c439e0774703084520736fe3c87168116c41538 (diff)
downloadgolang-9da9a1e02f7eda25def1c6fa807054493209e413.tar.gz
os: do not test error case of TestRemoveAll when root
Fixes issue 22. R=r1, r http://codereview.appspot.com/152073
Diffstat (limited to 'src/pkg/os')
-rw-r--r--src/pkg/os/path_test.go53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/pkg/os/path_test.go b/src/pkg/os/path_test.go
index 0baa90132..9b11ac163 100644
--- a/src/pkg/os/path_test.go
+++ b/src/pkg/os/path_test.go
@@ -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)
}