MemFSTest.ModifyExistingFile_InSubDir
parent
f412eaa60a
commit
52f2e5fec5
|
@ -481,7 +481,62 @@ func (t *MemFSTest) ModifyExistingFile_InRoot() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MemFSTest) ModifyExistingFile_InSubDir() {
|
func (t *MemFSTest) ModifyExistingFile_InSubDir() {
|
||||||
AssertTrue(false, "TODO")
|
var err error
|
||||||
|
var n int
|
||||||
|
var fi os.FileInfo
|
||||||
|
var stat *syscall.Stat_t
|
||||||
|
|
||||||
|
// Create a sub-directory.
|
||||||
|
dirName := path.Join(t.mfs.Dir(), "dir")
|
||||||
|
err = os.Mkdir(dirName, 0700)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
// Write a file.
|
||||||
|
fileName := path.Join(dirName, "foo")
|
||||||
|
|
||||||
|
createTime := t.clock.Now()
|
||||||
|
err = ioutil.WriteFile(fileName, []byte("Jello, world!"), 0600)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
// Simulate time advancing.
|
||||||
|
t.clock.AdvanceTime(time.Second)
|
||||||
|
|
||||||
|
// Open the file and modify it.
|
||||||
|
f, err := os.OpenFile(fileName, os.O_WRONLY, 0400)
|
||||||
|
t.toClose = append(t.toClose, f)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
modifyTime := t.clock.Now()
|
||||||
|
n, err = f.WriteAt([]byte("H"), 0)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(1, n)
|
||||||
|
|
||||||
|
// Simulate time advancing.
|
||||||
|
t.clock.AdvanceTime(time.Second)
|
||||||
|
|
||||||
|
// Stat the file.
|
||||||
|
fi, err = os.Stat(fileName)
|
||||||
|
stat = fi.Sys().(*syscall.Stat_t)
|
||||||
|
|
||||||
|
AssertEq(nil, err)
|
||||||
|
ExpectEq("foo", fi.Name())
|
||||||
|
ExpectEq(len("Hello, world!"), fi.Size())
|
||||||
|
ExpectEq(0600, fi.Mode())
|
||||||
|
ExpectEq(0, fi.ModTime().Sub(modifyTime))
|
||||||
|
ExpectFalse(fi.IsDir())
|
||||||
|
|
||||||
|
ExpectNe(0, stat.Ino)
|
||||||
|
ExpectEq(1, stat.Nlink)
|
||||||
|
ExpectEq(currentUid(), stat.Uid)
|
||||||
|
ExpectEq(currentGid(), stat.Gid)
|
||||||
|
ExpectEq(len("Hello, world!"), stat.Size)
|
||||||
|
ExpectEq(0, timespecToTime(stat.Mtimespec).Sub(modifyTime))
|
||||||
|
ExpectEq(0, timespecToTime(stat.Birthtimespec).Sub(createTime))
|
||||||
|
|
||||||
|
// Read the file back.
|
||||||
|
slice, err := ioutil.ReadFile(fileName)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
ExpectEq("Hello, world!", string(slice))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MemFSTest) UnlinkFile_Exists() {
|
func (t *MemFSTest) UnlinkFile_Exists() {
|
||||||
|
|
Loading…
Reference in New Issue