MemFSTest.RenameAcrossDirs_File
parent
bde0d1be29
commit
361e9e61f6
|
@ -1404,7 +1404,60 @@ func (t *MemFSTest) RenameWithinDir_SameName() {
|
|||
}
|
||||
|
||||
func (t *MemFSTest) RenameAcrossDirs_File() {
|
||||
AssertTrue(false, "TODO")
|
||||
var err error
|
||||
|
||||
// Create two parent directories.
|
||||
oldParentPath := path.Join(t.Dir, "old")
|
||||
newParentPath := path.Join(t.Dir, "new")
|
||||
|
||||
err = os.Mkdir(oldParentPath, 0700)
|
||||
AssertEq(nil, err)
|
||||
|
||||
err = os.Mkdir(newParentPath, 0700)
|
||||
AssertEq(nil, err)
|
||||
|
||||
// And a file within the first.
|
||||
oldPath := path.Join(oldParentPath, "foo")
|
||||
|
||||
err = ioutil.WriteFile(oldPath, []byte("taco"), 0400)
|
||||
AssertEq(nil, err)
|
||||
|
||||
// Rename it.
|
||||
newPath := path.Join(newParentPath, "bar")
|
||||
|
||||
err = os.Rename(oldPath, newPath)
|
||||
AssertEq(nil, err)
|
||||
|
||||
// The old name shouldn't work.
|
||||
_, err = os.Stat(oldPath)
|
||||
ExpectTrue(os.IsNotExist(err), "err: %v", err)
|
||||
|
||||
_, err = ioutil.ReadFile(oldPath)
|
||||
ExpectTrue(os.IsNotExist(err), "err: %v", err)
|
||||
|
||||
// The new name should.
|
||||
fi, err := os.Stat(newPath)
|
||||
AssertEq(nil, err)
|
||||
ExpectEq(len("taco"), fi.Size())
|
||||
ExpectEq(os.FileMode(0400), fi.Mode())
|
||||
|
||||
contents, err := ioutil.ReadFile(newPath)
|
||||
AssertEq(nil, err)
|
||||
ExpectEq("taco", string(contents))
|
||||
|
||||
// Check the old parent.
|
||||
entries, err := fusetesting.ReadDirPicky(oldParentPath)
|
||||
AssertEq(nil, err)
|
||||
AssertEq(0, len(entries))
|
||||
|
||||
// And the new one.
|
||||
entries, err = fusetesting.ReadDirPicky(newParentPath)
|
||||
AssertEq(nil, err)
|
||||
AssertEq(1, len(entries))
|
||||
fi = entries[0]
|
||||
|
||||
ExpectEq(path.Base(newPath), fi.Name())
|
||||
ExpectEq(os.FileMode(0400), fi.Mode())
|
||||
}
|
||||
|
||||
func (t *MemFSTest) RenameAcrossDirs_Directory() {
|
||||
|
|
Loading…
Reference in New Issue