Commit 2642d571 authored by Aaron Jacobs's avatar Aaron Jacobs

memfs_test: pass on Go 1.8 and above, too.

This was broken by golang/go@321c312d8246dec6889f5fe334b6193c320baf0e.
parent dfa49f55
// +build go1.8
package memfs_test
const atLeastGo18 = true
// +build !go1.8
package memfs_test
const atLeastGo18 = false
...@@ -1567,30 +1567,21 @@ func (t *MemFSTest) RenameOverExistingDirectory() { ...@@ -1567,30 +1567,21 @@ func (t *MemFSTest) RenameOverExistingDirectory() {
err = os.Mkdir(newPath, 0600) err = os.Mkdir(newPath, 0600)
AssertEq(nil, err) AssertEq(nil, err)
// Renaming over the non-empty one shouldn't work. // Renaming over the non-empty directory shouldn't work.
err = os.Rename(newPath, oldPath) err = os.Rename(newPath, oldPath)
ExpectThat(err, Error(HasSubstr("not empty"))) ExpectThat(err, Error(MatchesRegexp("not empty|file exists")))
// But the other way around should. // As of Go 1.8 this shouldn't work the other way around either (see
err = os.Rename(oldPath, newPath) // https://github.com/golang/go/commit/321c312).
AssertEq(nil, err) if atLeastGo18 {
err = os.Rename(oldPath, newPath)
// Check the parent listing. ExpectThat(err, Error(HasSubstr("file exists")))
entries, err := fusetesting.ReadDirPicky(t.Dir)
AssertEq(nil, err)
AssertEq(1, len(entries))
fi := entries[0]
ExpectEq(path.Base(newPath), fi.Name()) // Both should still be present in the parent listing.
ExpectEq(os.FileMode(0700)|os.ModeDir, fi.Mode()) entries, err := fusetesting.ReadDirPicky(t.Dir)
AssertEq(nil, err)
// And the directory itself. ExpectEq(2, len(entries))
entries, err = fusetesting.ReadDirPicky(newPath) }
AssertEq(nil, err)
AssertEq(1, len(entries))
fi = entries[0]
ExpectEq("child", fi.Name())
} }
func (t *MemFSTest) RenameOverExisting_WrongType() { func (t *MemFSTest) RenameOverExisting_WrongType() {
...@@ -1605,9 +1596,9 @@ func (t *MemFSTest) RenameOverExisting_WrongType() { ...@@ -1605,9 +1596,9 @@ func (t *MemFSTest) RenameOverExisting_WrongType() {
err = os.Mkdir(dirPath, 0700) err = os.Mkdir(dirPath, 0700)
AssertEq(nil, err) AssertEq(nil, err)
// Renaming one over the other shouldn't work. // Renaming either over the other shouldn't work.
err = os.Rename(filePath, dirPath) err = os.Rename(filePath, dirPath)
ExpectThat(err, Error(HasSubstr("is a directory"))) ExpectThat(err, Error(MatchesRegexp("is a directory|file exists")))
err = os.Rename(dirPath, filePath) err = os.Rename(dirPath, filePath)
ExpectThat(err, Error(HasSubstr("not a directory"))) ExpectThat(err, Error(HasSubstr("not a directory")))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment