os: implement and smoketest os.Chmod

This commit is contained in:
Dan Kegel
2021-12-04 13:50:32 -08:00
committed by Ron Evans
parent e668c8c1a7
commit be7bbba4ca
4 changed files with 106 additions and 16 deletions
+26
View File
@@ -25,6 +25,32 @@ func newFile(testName string, t *testing.T) (f *File) {
return
}
func checkMode(t *testing.T, path string, mode FileMode) {
dir, err := Stat(path)
if err != nil {
t.Fatalf("Stat %q (looking for mode %#o): %s", path, mode, err)
}
if dir.Mode()&ModePerm != mode {
t.Errorf("Stat %q: mode %#o want %#o", path, dir.Mode(), mode)
}
}
func TestChmod(t *testing.T) {
f := newFile("TestChmod", t)
defer Remove(f.Name())
defer f.Close()
// Creation mode is read write
fm := FileMode(0456)
if runtime.GOOS == "windows" {
fm = FileMode(0444) // read-only file
}
if err := Chmod(f.Name(), fm); err != nil {
t.Fatalf("chmod %s %#o: %s", f.Name(), fm, err)
}
checkMode(t, f.Name(), fm)
}
func TestReadAt(t *testing.T) {
if runtime.GOOS == "windows" {
t.Log("TODO: implement Pread for Windows")