Fixed memfs_test.go.
parent
eecd0fb964
commit
a6dd3d2147
|
@ -89,7 +89,7 @@ type MemFSTest struct {
|
||||||
func init() { RegisterTestSuite(&MemFSTest{}) }
|
func init() { RegisterTestSuite(&MemFSTest{}) }
|
||||||
|
|
||||||
func (t *MemFSTest) SetUp(ti *TestInfo) {
|
func (t *MemFSTest) SetUp(ti *TestInfo) {
|
||||||
t.Server = memfs.NewMemFS(currentUid(), currentGid(), &t.Clock)
|
t.Server = memfs.NewMemFS(currentUid(), currentGid())
|
||||||
t.SampleTest.SetUp(ti)
|
t.SampleTest.SetUp(ti)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,17 +112,11 @@ func (t *MemFSTest) Mkdir_OneLevel() {
|
||||||
|
|
||||||
dirName := path.Join(t.Dir, "dir")
|
dirName := path.Join(t.Dir, "dir")
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// Create a directory within the root.
|
// Create a directory within the root.
|
||||||
createTime := t.Clock.Now()
|
createTime := time.Now()
|
||||||
err = os.Mkdir(dirName, 0754)
|
err = os.Mkdir(dirName, 0754)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// Stat the directory.
|
// Stat the directory.
|
||||||
fi, err = os.Stat(dirName)
|
fi, err = os.Stat(dirName)
|
||||||
stat = fi.Sys().(*syscall.Stat_t)
|
stat = fi.Sys().(*syscall.Stat_t)
|
||||||
|
@ -174,17 +168,11 @@ func (t *MemFSTest) Mkdir_TwoLevels() {
|
||||||
err = os.Mkdir(path.Join(t.Dir, "parent"), 0700)
|
err = os.Mkdir(path.Join(t.Dir, "parent"), 0700)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// Create a child of that directory.
|
// Create a child of that directory.
|
||||||
createTime := t.Clock.Now()
|
createTime := time.Now()
|
||||||
err = os.Mkdir(path.Join(t.Dir, "parent/dir"), 0754)
|
err = os.Mkdir(path.Join(t.Dir, "parent/dir"), 0754)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// Stat the directory.
|
// Stat the directory.
|
||||||
fi, err = os.Stat(path.Join(t.Dir, "parent/dir"))
|
fi, err = os.Stat(path.Join(t.Dir, "parent/dir"))
|
||||||
stat = fi.Sys().(*syscall.Stat_t)
|
stat = fi.Sys().(*syscall.Stat_t)
|
||||||
|
@ -290,13 +278,10 @@ func (t *MemFSTest) CreateNewFile_InRoot() {
|
||||||
fileName := path.Join(t.Dir, "foo")
|
fileName := path.Join(t.Dir, "foo")
|
||||||
const contents = "Hello\x00world"
|
const contents = "Hello\x00world"
|
||||||
|
|
||||||
createTime := t.Clock.Now()
|
createTime := time.Now()
|
||||||
err = ioutil.WriteFile(fileName, []byte(contents), 0400)
|
err = ioutil.WriteFile(fileName, []byte(contents), 0400)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// Stat it.
|
// Stat it.
|
||||||
fi, err = os.Stat(fileName)
|
fi, err = os.Stat(fileName)
|
||||||
stat = fi.Sys().(*syscall.Stat_t)
|
stat = fi.Sys().(*syscall.Stat_t)
|
||||||
|
@ -335,13 +320,10 @@ func (t *MemFSTest) CreateNewFile_InSubDir() {
|
||||||
fileName := path.Join(dirName, "foo")
|
fileName := path.Join(dirName, "foo")
|
||||||
const contents = "Hello\x00world"
|
const contents = "Hello\x00world"
|
||||||
|
|
||||||
createTime := t.Clock.Now()
|
createTime := time.Now()
|
||||||
err = ioutil.WriteFile(fileName, []byte(contents), 0400)
|
err = ioutil.WriteFile(fileName, []byte(contents), 0400)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// Stat it.
|
// Stat it.
|
||||||
fi, err = os.Stat(fileName)
|
fi, err = os.Stat(fileName)
|
||||||
stat = fi.Sys().(*syscall.Stat_t)
|
stat = fi.Sys().(*syscall.Stat_t)
|
||||||
|
@ -375,26 +357,20 @@ func (t *MemFSTest) ModifyExistingFile_InRoot() {
|
||||||
// Write a file.
|
// Write a file.
|
||||||
fileName := path.Join(t.Dir, "foo")
|
fileName := path.Join(t.Dir, "foo")
|
||||||
|
|
||||||
createTime := t.Clock.Now()
|
createTime := time.Now()
|
||||||
err = ioutil.WriteFile(fileName, []byte("Hello, world!"), 0600)
|
err = ioutil.WriteFile(fileName, []byte("Hello, world!"), 0600)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// Open the file and modify it.
|
// Open the file and modify it.
|
||||||
f, err := os.OpenFile(fileName, os.O_WRONLY, 0400)
|
f, err := os.OpenFile(fileName, os.O_WRONLY, 0400)
|
||||||
t.ToClose = append(t.ToClose, f)
|
t.ToClose = append(t.ToClose, f)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
modifyTime := t.Clock.Now()
|
modifyTime := time.Now()
|
||||||
n, err = f.WriteAt([]byte("H"), 0)
|
n, err = f.WriteAt([]byte("H"), 0)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
AssertEq(1, n)
|
AssertEq(1, n)
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// Stat the file.
|
// Stat the file.
|
||||||
fi, err = os.Stat(fileName)
|
fi, err = os.Stat(fileName)
|
||||||
stat = fi.Sys().(*syscall.Stat_t)
|
stat = fi.Sys().(*syscall.Stat_t)
|
||||||
|
@ -433,26 +409,20 @@ func (t *MemFSTest) ModifyExistingFile_InSubDir() {
|
||||||
// Write a file.
|
// Write a file.
|
||||||
fileName := path.Join(dirName, "foo")
|
fileName := path.Join(dirName, "foo")
|
||||||
|
|
||||||
createTime := t.Clock.Now()
|
createTime := time.Now()
|
||||||
err = ioutil.WriteFile(fileName, []byte("Hello, world!"), 0600)
|
err = ioutil.WriteFile(fileName, []byte("Hello, world!"), 0600)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// Open the file and modify it.
|
// Open the file and modify it.
|
||||||
f, err := os.OpenFile(fileName, os.O_WRONLY, 0400)
|
f, err := os.OpenFile(fileName, os.O_WRONLY, 0400)
|
||||||
t.ToClose = append(t.ToClose, f)
|
t.ToClose = append(t.ToClose, f)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
modifyTime := t.Clock.Now()
|
modifyTime := time.Now()
|
||||||
n, err = f.WriteAt([]byte("H"), 0)
|
n, err = f.WriteAt([]byte("H"), 0)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
AssertEq(1, n)
|
AssertEq(1, n)
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// Stat the file.
|
// Stat the file.
|
||||||
fi, err = os.Stat(fileName)
|
fi, err = os.Stat(fileName)
|
||||||
stat = fi.Sys().(*syscall.Stat_t)
|
stat = fi.Sys().(*syscall.Stat_t)
|
||||||
|
@ -574,17 +544,11 @@ func (t *MemFSTest) Rmdir_Empty() {
|
||||||
err = os.MkdirAll(path.Join(t.Dir, "foo/bar"), 0754)
|
err = os.MkdirAll(path.Join(t.Dir, "foo/bar"), 0754)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// Remove the leaf.
|
// Remove the leaf.
|
||||||
rmTime := t.Clock.Now()
|
rmTime := time.Now()
|
||||||
err = os.Remove(path.Join(t.Dir, "foo/bar"))
|
err = os.Remove(path.Join(t.Dir, "foo/bar"))
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// There should be nothing left in the parent.
|
// There should be nothing left in the parent.
|
||||||
entries, err = fusetesting.ReadDirPicky(path.Join(t.Dir, "foo"))
|
entries, err = fusetesting.ReadDirPicky(path.Join(t.Dir, "foo"))
|
||||||
|
|
||||||
|
@ -618,13 +582,10 @@ func (t *MemFSTest) Rmdir_OpenedForReading() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Create a directory.
|
// Create a directory.
|
||||||
createTime := t.Clock.Now()
|
createTime := time.Now()
|
||||||
err = os.Mkdir(path.Join(t.Dir, "dir"), 0700)
|
err = os.Mkdir(path.Join(t.Dir, "dir"), 0700)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
// Simulate time advancing.
|
|
||||||
t.Clock.AdvanceTime(time.Second)
|
|
||||||
|
|
||||||
// Open the directory for reading.
|
// Open the directory for reading.
|
||||||
f, err := os.Open(path.Join(t.Dir, "dir"))
|
f, err := os.Open(path.Join(t.Dir, "dir"))
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
Loading…
Reference in New Issue