Skip to content

Commit 1971e1b

Browse files
committed
os: do not test error case of TestRemoveAll when root
Fixes #22. R=r1, r https://golang.org/cl/152073
1 parent 364e564 commit 1971e1b

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

src/pkg/os/path_test.go

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,35 +104,38 @@ func TestRemoveAll(t *testing.T) {
104104
t.Fatalf("Lstat %q succeeded after RemoveAll (second)", path)
105105
}
106106

107-
// Make directory with file and subdirectory and trigger error.
108-
if err = MkdirAll(dpath, 0777); err != nil {
109-
t.Fatalf("MkdirAll %q: %s", dpath, err)
110-
}
107+
if Getuid() != 0 { // Test fails as root
108+
// Make directory with file and subdirectory and trigger error.
109+
if err = MkdirAll(dpath, 0777); err != nil {
110+
t.Fatalf("MkdirAll %q: %s", dpath, err)
111+
}
111112

112-
for _, s := range []string{fpath, dpath + "/file1", path + "/zzz"} {
113-
fd, err = Open(s, O_WRONLY|O_CREAT, 0666);
114-
if err != nil {
115-
t.Fatalf("create %q: %s", s, err)
113+
for _, s := range []string{fpath, dpath + "/file1", path + "/zzz"} {
114+
fd, err = Open(s, O_WRONLY|O_CREAT, 0666);
115+
if err != nil {
116+
t.Fatalf("create %q: %s", s, err)
117+
}
118+
fd.Close();
116119
}
117-
fd.Close();
118-
}
119-
if err = Chmod(dpath, 0); err != nil {
120-
t.Fatalf("Chmod %q 0: %s", dpath, err)
121-
}
122-
if err = RemoveAll(path); err == nil {
123-
_, err := Lstat(path);
124-
if err == nil {
125-
t.Errorf("Can lstat %q after supposed RemoveAll", path)
120+
if err = Chmod(dpath, 0); err != nil {
121+
t.Fatalf("Chmod %q 0: %s", dpath, err)
122+
}
123+
if err = RemoveAll(path); err == nil {
124+
_, err := Lstat(path);
125+
if err == nil {
126+
t.Errorf("Can lstat %q after supposed RemoveAll", path)
127+
}
128+
t.Fatalf("RemoveAll %q succeeded with chmod 0 subdirectory", path, err);
129+
}
130+
perr, ok := err.(*PathError);
131+
if !ok {
132+
t.Fatalf("RemoveAll %q returned %T not *PathError", path, err)
133+
}
134+
if perr.Path != dpath {
135+
t.Fatalf("RemoveAll %q failed at %q not %q", path, perr.Path, dpath)
126136
}
127-
t.Fatalf("RemoveAll %q succeeded with chmod 0 subdirectory", path, err);
128-
}
129-
perr, ok := err.(*PathError);
130-
if !ok {
131-
t.Fatalf("RemoveAll %q returned %T not *PathError", path, err)
132-
}
133-
if perr.Path != dpath {
134-
t.Fatalf("RemoveAll %q failed at %q not %q", path, perr.Path, dpath)
135137
}
138+
136139
if err = Chmod(dpath, 0777); err != nil {
137140
t.Fatalf("Chmod %q 0777: %s", dpath, err)
138141
}

0 commit comments

Comments
 (0)