From 2642d571aa800c9ddca51e63800a57046970ce96 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 19 Dec 2016 15:07:56 +1100 Subject: [PATCH] memfs_test: pass on Go 1.8 and above, too. This was broken by golang/go@321c312d8246dec6889f5fe334b6193c320baf0e. --- samples/memfs/memfs_go18_test.go | 5 ++++ samples/memfs/memfs_others_test.go | 5 ++++ samples/memfs/memfs_test.go | 37 +++++++++++------------------- 3 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 samples/memfs/memfs_go18_test.go create mode 100644 samples/memfs/memfs_others_test.go diff --git a/samples/memfs/memfs_go18_test.go b/samples/memfs/memfs_go18_test.go new file mode 100644 index 0000000..b8d1516 --- /dev/null +++ b/samples/memfs/memfs_go18_test.go @@ -0,0 +1,5 @@ +// +build go1.8 + +package memfs_test + +const atLeastGo18 = true diff --git a/samples/memfs/memfs_others_test.go b/samples/memfs/memfs_others_test.go new file mode 100644 index 0000000..88f0ed3 --- /dev/null +++ b/samples/memfs/memfs_others_test.go @@ -0,0 +1,5 @@ +// +build !go1.8 + +package memfs_test + +const atLeastGo18 = false diff --git a/samples/memfs/memfs_test.go b/samples/memfs/memfs_test.go index e2a65e4..977dae3 100644 --- a/samples/memfs/memfs_test.go +++ b/samples/memfs/memfs_test.go @@ -1567,30 +1567,21 @@ func (t *MemFSTest) RenameOverExistingDirectory() { err = os.Mkdir(newPath, 0600) 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) - ExpectThat(err, Error(HasSubstr("not empty"))) + ExpectThat(err, Error(MatchesRegexp("not empty|file exists"))) - // But the other way around should. - err = os.Rename(oldPath, newPath) - AssertEq(nil, err) + // As of Go 1.8 this shouldn't work the other way around either (see + // https://github.com/golang/go/commit/321c312). + if atLeastGo18 { + err = os.Rename(oldPath, newPath) + ExpectThat(err, Error(HasSubstr("file exists"))) - // Check the parent listing. - entries, err := fusetesting.ReadDirPicky(t.Dir) - AssertEq(nil, err) - AssertEq(1, len(entries)) - fi := entries[0] - - ExpectEq(path.Base(newPath), fi.Name()) - ExpectEq(os.FileMode(0700)|os.ModeDir, fi.Mode()) - - // And the directory itself. - entries, err = fusetesting.ReadDirPicky(newPath) - AssertEq(nil, err) - AssertEq(1, len(entries)) - fi = entries[0] - - ExpectEq("child", fi.Name()) + // Both should still be present in the parent listing. + entries, err := fusetesting.ReadDirPicky(t.Dir) + AssertEq(nil, err) + ExpectEq(2, len(entries)) + } } func (t *MemFSTest) RenameOverExisting_WrongType() { @@ -1605,9 +1596,9 @@ func (t *MemFSTest) RenameOverExisting_WrongType() { err = os.Mkdir(dirPath, 0700) AssertEq(nil, err) - // Renaming one over the other shouldn't work. + // Renaming either over the other shouldn't work. 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) ExpectThat(err, Error(HasSubstr("not a directory")))