MemFSTest.CreateNewFile_InRoot

geesefs-0-30-9
Aaron Jacobs 2015-03-04 15:10:26 +11:00
parent 9c585268b0
commit 87f8ec9ead
1 changed files with 39 additions and 1 deletions

View File

@ -309,7 +309,45 @@ func (t *MemFSTest) Mkdir_PermissionDenied() {
}
func (t *MemFSTest) CreateNewFile_InRoot() {
AssertTrue(false, "TODO")
var err error
var fi os.FileInfo
var stat *syscall.Stat_t
fileName := path.Join(t.mfs.Dir(), "foo")
const contents = "Hello\x00world"
// Write a file.
createTime := t.clock.Now()
err = ioutil.WriteFile(fileName, []byte(contents), 0400)
AssertEq(nil, err)
// Simulate time advancing.
t.clock.AdvanceTime(time.Second)
// Stat it.
fi, err = os.Stat(fileName)
stat = fi.Sys().(*syscall.Stat_t)
AssertEq(nil, err)
ExpectEq("foo", fi.Name())
ExpectEq(len(contents), fi.Size())
ExpectEq(0400, fi.Mode())
ExpectEq(0, fi.ModTime().Sub(createTime))
ExpectFalse(fi.IsDir())
ExpectNe(0, stat.Ino)
ExpectEq(1, stat.Nlink)
ExpectEq(currentUid(), stat.Uid)
ExpectEq(currentGid(), stat.Gid)
ExpectEq(len(contents), stat.Size)
ExpectEq(0, timespecToTime(stat.Atimespec).Sub(createTime))
ExpectEq(0, timespecToTime(stat.Mtimespec).Sub(createTime))
ExpectEq(0, timespecToTime(stat.Ctimespec).Sub(createTime))
// Read it back.
slice, err := ioutil.ReadFile(fileName)
AssertEq(nil, err)
ExpectEq(contents, string(slice))
}
func (t *MemFSTest) CreateNewFile_InSubDir() {