Added better tests for statting new dirs.

geesefs-0-30-9
Aaron Jacobs 2015-03-03 10:37:09 +11:00
parent 79d87d5956
commit 605a52de92
1 changed files with 22 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"os"
"path"
"strings"
"syscall"
"testing"
"time"
@ -22,6 +23,16 @@ import (
func TestMemFS(t *testing.T) { RunTests(t) }
////////////////////////////////////////////////////////////////////////
// Helpers
////////////////////////////////////////////////////////////////////////
func currentUid() uint32
func currentGid() uint32
func timespecToTime(ts syscall.Timespec) time.Time
////////////////////////////////////////////////////////////////////////
// Boilerplate
////////////////////////////////////////////////////////////////////////
@ -97,6 +108,8 @@ func (t *MemFSTest) ContentsOfEmptyFileSystem() {
func (t *MemFSTest) Mkdir() {
var err error
var fi os.FileInfo
var stat *syscall.Stat_t
dirName := path.Join(t.mfs.Dir(), "dir")
// Create a directory within the root.
@ -109,6 +122,7 @@ func (t *MemFSTest) Mkdir() {
// Stat the directory.
fi, err = os.Stat(dirName)
stat = fi.Sys().(*syscall.Stat_t)
AssertEq(nil, err)
ExpectEq("dir", fi.Name())
@ -117,6 +131,14 @@ func (t *MemFSTest) Mkdir() {
ExpectEq(0, fi.ModTime().Sub(createTime))
ExpectTrue(fi.IsDir())
ExpectEq(1, stat.Nlink)
ExpectEq(currentUid(), stat.Uid)
ExpectEq(currentGid(), stat.Gid)
ExpectEq(0, stat.Size)
ExpectEq(createTime, timespecToTime(stat.Atimespec))
ExpectEq(createTime, timespecToTime(stat.Mtimespec))
ExpectEq(createTime, timespecToTime(stat.Ctimespec))
// Read the directory.
entries, err := ioutil.ReadDir(dirName)