From f0ae4d753eabc73dff63e4d8c9bc964161598dea Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 24 Mar 2015 08:39:22 +1100 Subject: [PATCH] Recategorized tests. --- samples/flushfs/flush_fs_test.go | 216 +++++++++++++++---------------- 1 file changed, 106 insertions(+), 110 deletions(-) diff --git a/samples/flushfs/flush_fs_test.go b/samples/flushfs/flush_fs_test.go index 564c118..8e82a04 100644 --- a/samples/flushfs/flush_fs_test.go +++ b/samples/flushfs/flush_fs_test.go @@ -119,9 +119,17 @@ func dup2(oldfd int, newfd int) (err error) { } //////////////////////////////////////////////////////////////////////// -// Tests +// No errors //////////////////////////////////////////////////////////////////////// +type NoErrorsTest struct { + flushFSTest +} + +func init() { RegisterTestSuite(&NoErrorsTest{}) } + +func (t *NoErrorsTest) SetUp(ti *TestInfo) + func (t *FlushFSTest) CloseReports_ReadWrite() { var n int var off int64 @@ -304,24 +312,6 @@ func (t *FlushFSTest) CloseReports_MultipleTimes_OverlappingFileHandles() { AssertThat(t.getFsyncs(), ElementsAre()) } -func (t *FlushFSTest) CloseError() { - var err error - - // Open the file. - t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_RDWR, 0) - AssertEq(nil, err) - - // Configure a flush error. - t.setFlushError(fuse.ENOENT) - - // Close the file. - err = t.f1.Close() - t.f1 = nil - - AssertNe(nil, err) - ExpectThat(err, Error(HasSubstr("no such file"))) -} - func (t *FlushFSTest) FsyncReports() { var n int var err error @@ -361,23 +351,6 @@ func (t *FlushFSTest) FsyncReports() { AssertThat(t.getFsyncs(), ElementsAre("taco", "tacos")) } -func (t *FlushFSTest) FsyncError() { - var err error - - // Open the file. - t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_RDWR, 0) - AssertEq(nil, err) - - // Configure an fsync error. - t.setFsyncError(fuse.ENOENT) - - // Fsync. - err = t.f1.Sync() - - AssertNe(nil, err) - ExpectThat(err, Error(HasSubstr("no such file"))) -} - func (t *FlushFSTest) Dup() { var n int var err error @@ -442,45 +415,6 @@ func (t *FlushFSTest) Dup() { ExpectThat(t.getFsyncs(), ElementsAre()) } -func (t *FlushFSTest) Dup_FlushError() { - var err error - - // Open the file. - t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_WRONLY, 0) - AssertEq(nil, err) - - fd1 := t.f1.Fd() - - // Use dup(2) to get another copy. - fd2, err := syscall.Dup(int(fd1)) - AssertEq(nil, err) - - t.f2 = os.NewFile(uintptr(fd2), t.f1.Name()) - - // Configure a flush error. - t.setFlushError(fuse.ENOENT) - - // Close by the first handle. On OS X, where the semantics of file handles - // are different (cf. https://github.com/osxfuse/osxfuse/issues/199), this - // does not result in an error. - err = t.f1.Close() - t.f1 = nil - - if runtime.GOOS == "darwin" { - AssertEq(nil, err) - } else { - AssertNe(nil, err) - ExpectThat(err, Error(HasSubstr("no such file"))) - } - - // Close by the second handle. - err = t.f2.Close() - t.f2 = nil - - AssertNe(nil, err) - ExpectThat(err, Error(HasSubstr("no such file"))) -} - func (t *FlushFSTest) Dup2() { var n int var err error @@ -510,29 +444,6 @@ func (t *FlushFSTest) Dup2() { ExpectThat(t.getFsyncs(), ElementsAre()) } -func (t *FlushFSTest) Dup2_FlushError() { - var err error - - // Open the file. - t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_WRONLY, 0) - AssertEq(nil, err) - - // Open and unlink some temporary file. - t.f2, err = ioutil.TempFile("", "") - AssertEq(nil, err) - - err = os.Remove(t.f2.Name()) - AssertEq(nil, err) - - // Configure a flush error. - t.setFlushError(fuse.ENOENT) - - // Duplicate the temporary file descriptor on top of the file from our file - // system. We shouldn't see the flush error. - err = dup2(int(t.f2.Fd()), int(t.f1.Fd())) - ExpectEq(nil, err) -} - func (t *FlushFSTest) Mmap_MunmapBeforeClose() { var n int var err error @@ -651,18 +562,6 @@ func (t *FlushFSTest) Directory() { AssertTrue(false, "TODO") } -//////////////////////////////////////////////////////////////////////// -// No errors -//////////////////////////////////////////////////////////////////////// - -type NoErrorsTest struct { - flushFSTest -} - -func init() { RegisterTestSuite(&NoErrorsTest{}) } - -func (t *NoErrorsTest) SetUp(ti *TestInfo) - //////////////////////////////////////////////////////////////////////// // Flush error //////////////////////////////////////////////////////////////////////// @@ -675,6 +574,86 @@ func init() { RegisterTestSuite(&FlushErrorTest{}) } func (t *FlushErrorTest) SetUp(ti *TestInfo) +func (t *FlushFSTest) CloseError() { + var err error + + // Open the file. + t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_RDWR, 0) + AssertEq(nil, err) + + // Configure a flush error. + t.setFlushError(fuse.ENOENT) + + // Close the file. + err = t.f1.Close() + t.f1 = nil + + AssertNe(nil, err) + ExpectThat(err, Error(HasSubstr("no such file"))) +} + +func (t *FlushFSTest) Dup_FlushError() { + var err error + + // Open the file. + t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_WRONLY, 0) + AssertEq(nil, err) + + fd1 := t.f1.Fd() + + // Use dup(2) to get another copy. + fd2, err := syscall.Dup(int(fd1)) + AssertEq(nil, err) + + t.f2 = os.NewFile(uintptr(fd2), t.f1.Name()) + + // Configure a flush error. + t.setFlushError(fuse.ENOENT) + + // Close by the first handle. On OS X, where the semantics of file handles + // are different (cf. https://github.com/osxfuse/osxfuse/issues/199), this + // does not result in an error. + err = t.f1.Close() + t.f1 = nil + + if runtime.GOOS == "darwin" { + AssertEq(nil, err) + } else { + AssertNe(nil, err) + ExpectThat(err, Error(HasSubstr("no such file"))) + } + + // Close by the second handle. + err = t.f2.Close() + t.f2 = nil + + AssertNe(nil, err) + ExpectThat(err, Error(HasSubstr("no such file"))) +} + +func (t *FlushFSTest) Dup2_FlushError() { + var err error + + // Open the file. + t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_WRONLY, 0) + AssertEq(nil, err) + + // Open and unlink some temporary file. + t.f2, err = ioutil.TempFile("", "") + AssertEq(nil, err) + + err = os.Remove(t.f2.Name()) + AssertEq(nil, err) + + // Configure a flush error. + t.setFlushError(fuse.ENOENT) + + // Duplicate the temporary file descriptor on top of the file from our file + // system. We shouldn't see the flush error. + err = dup2(int(t.f2.Fd()), int(t.f1.Fd())) + ExpectEq(nil, err) +} + //////////////////////////////////////////////////////////////////////// // Fsync error //////////////////////////////////////////////////////////////////////// @@ -686,3 +665,20 @@ type FsyncErrorTest struct { func init() { RegisterTestSuite(&FsyncErrorTest{}) } func (t *FsyncErrorTest) SetUp(ti *TestInfo) + +func (t *FlushFSTest) FsyncError() { + var err error + + // Open the file. + t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_RDWR, 0) + AssertEq(nil, err) + + // Configure an fsync error. + t.setFsyncError(fuse.ENOENT) + + // Fsync. + err = t.f1.Sync() + + AssertNe(nil, err) + ExpectThat(err, Error(HasSubstr("no such file"))) +}