From 917ea6ac57bc9548b27c6adddcd05b6e1965a5cb Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 8 May 2017 12:20:39 +0100 Subject: [PATCH] mountlib: make tests work under all platforms --- cmd/mountlib/mounttest/dir.go | 2 - cmd/mountlib/mounttest/file.go | 2 - cmd/mountlib/mounttest/fs.go | 2 - cmd/mountlib/mounttest/read.go | 84 --------------------------------- cmd/mountlib/mounttest/write.go | 42 ----------------- 5 files changed, 132 deletions(-) diff --git a/cmd/mountlib/mounttest/dir.go b/cmd/mountlib/mounttest/dir.go index d5f6a222e..a1c52f328 100644 --- a/cmd/mountlib/mounttest/dir.go +++ b/cmd/mountlib/mounttest/dir.go @@ -1,5 +1,3 @@ -// +build linux darwin freebsd - package mounttest import ( diff --git a/cmd/mountlib/mounttest/file.go b/cmd/mountlib/mounttest/file.go index b936c10fe..5a03c528c 100644 --- a/cmd/mountlib/mounttest/file.go +++ b/cmd/mountlib/mounttest/file.go @@ -1,5 +1,3 @@ -// +build linux darwin freebsd - package mounttest import ( diff --git a/cmd/mountlib/mounttest/fs.go b/cmd/mountlib/mounttest/fs.go index 6ed44c6c7..fb3e268f6 100644 --- a/cmd/mountlib/mounttest/fs.go +++ b/cmd/mountlib/mounttest/fs.go @@ -1,5 +1,3 @@ -// +build linux darwin freebsd - // Test suite for rclonefs package mounttest diff --git a/cmd/mountlib/mounttest/read.go b/cmd/mountlib/mounttest/read.go index d09c40d64..102d5f02d 100644 --- a/cmd/mountlib/mounttest/read.go +++ b/cmd/mountlib/mounttest/read.go @@ -1,12 +1,9 @@ -// +build linux darwin freebsd - package mounttest import ( "io" "io/ioutil" "os" - "syscall" "testing" "github.com/stretchr/testify/assert" @@ -37,87 +34,6 @@ func TestReadByByte(t *testing.T) { run.rm(t, "testfile") } -func TestReadChecksum(t *testing.T) { - run.skipIfNoFUSE(t) - - // create file big enough so we exceed any single FUSE read - // request - b := make([]rune, 3*128*1024) - for i := range b { - b[i] = 'r' - } - run.createFile(t, "bigfile", string(b)) - - // The hash comparison would fail in Flush, if we did not - // ensure we read the whole file - fd, err := os.Open(run.path("bigfile")) - assert.NoError(t, err) - buf := make([]byte, 10) - _, err = io.ReadFull(fd, buf) - assert.NoError(t, err) - err = fd.Close() - assert.NoError(t, err) - - // The hash comparison would fail, because we only read parts - // of the file - fd, err = os.Open(run.path("bigfile")) - assert.NoError(t, err) - // read at start - _, err = io.ReadFull(fd, buf) - assert.NoError(t, err) - // read at end - _, err = fd.Seek(int64(len(b)-len(buf)), 0) - assert.NoError(t, err) - _, err = io.ReadFull(fd, buf) - // ensure we don't compare hashes - err = fd.Close() - assert.NoError(t, err) - - run.rm(t, "bigfile") -} - -// Test double close -func TestReadFileDoubleClose(t *testing.T) { - run.skipIfNoFUSE(t) - - run.createFile(t, "testdoubleclose", "hello") - - in, err := os.Open(run.path("testdoubleclose")) - assert.NoError(t, err) - fd := in.Fd() - - fd1, err := syscall.Dup(int(fd)) - assert.NoError(t, err) - - fd2, err := syscall.Dup(int(fd)) - assert.NoError(t, err) - - // close one of the dups - should produce no error - err = syscall.Close(fd1) - assert.NoError(t, err) - - // read from the file - buf := make([]byte, 1) - _, err = in.Read(buf) - assert.NoError(t, err) - - // close it - err = in.Close() - assert.NoError(t, err) - - // read from the other dup - should produce no error as this - // file is now buffered - n, err := syscall.Read(fd2, buf) - assert.NoError(t, err) - assert.Equal(t, 1, n) - - // close the dup - should not produce an error - err = syscall.Close(fd2) - assert.NoError(t, err, "input/output error") - - run.rm(t, "testdoubleclose") -} - // Test seeking func TestReadSeek(t *testing.T) { run.skipIfNoFUSE(t) diff --git a/cmd/mountlib/mounttest/write.go b/cmd/mountlib/mounttest/write.go index 58e175ee4..fbf44c990 100644 --- a/cmd/mountlib/mounttest/write.go +++ b/cmd/mountlib/mounttest/write.go @@ -1,10 +1,7 @@ -// +build linux darwin freebsd - package mounttest import ( "os" - "syscall" "testing" "time" @@ -68,45 +65,6 @@ func TestWriteFileOverwrite(t *testing.T) { run.rm(t, "testwrite") } -// Test double close -func TestWriteFileDoubleClose(t *testing.T) { - run.skipIfNoFUSE(t) - - out, err := os.Create(run.path("testdoubleclose")) - assert.NoError(t, err) - fd := out.Fd() - - fd1, err := syscall.Dup(int(fd)) - assert.NoError(t, err) - - fd2, err := syscall.Dup(int(fd)) - assert.NoError(t, err) - - // close one of the dups - should produce no error - err = syscall.Close(fd1) - assert.NoError(t, err) - - // write to the file - buf := []byte("hello") - n, err := out.Write(buf) - assert.NoError(t, err) - assert.Equal(t, 5, n) - - // close it - err = out.Close() - assert.NoError(t, err) - - // write to the other dup - should produce an error - n, err = syscall.Write(fd2, buf) - assert.Error(t, err, "input/output error") - - // close the dup - should produce an error - err = syscall.Close(fd2) - assert.Error(t, err, "input/output error") - - run.rm(t, "testdoubleclose") -} - // Test Fsync // // NB the code for this is in file.go rather than write.go