Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

Fix tests when FUSE isn't present

Nick Craig-Wood9e7ddd5efcf5
diff --git a/cmd/mount/dir_test.go b/cmd/mount/dir_test.go
index 7b4f71438..b8e49dc79 100644
--- a/cmd/mount/dir_test.go
+++ b/cmd/mount/dir_test.go
@@ -11,6 +11,8 @@ import (
)
func TestDirLs(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
run.checkDir(t, "")
run.mkdir(t, "a directory")
@@ -25,6 +27,8 @@ func TestDirLs(t *testing.T) {
}
func TestDirCreateAndRemoveDir(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
run.mkdir(t, "dir")
run.mkdir(t, "dir/subdir")
run.checkDir(t, "dir/|dir/subdir/")
@@ -41,6 +45,8 @@ func TestDirCreateAndRemoveDir(t *testing.T) {
}
func TestDirCreateAndRemoveFile(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
run.mkdir(t, "dir")
run.createFile(t, "dir/file", "potato")
run.checkDir(t, "dir/|dir/file 6")
@@ -58,6 +64,8 @@ func TestDirCreateAndRemoveFile(t *testing.T) {
}
func TestDirRenameFile(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
run.mkdir(t, "dir")
run.createFile(t, "file", "potato")
run.checkDir(t, "dir/|file 6")
@@ -76,6 +84,8 @@ func TestDirRenameFile(t *testing.T) {
}
func TestDirRenameEmptyDir(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
run.mkdir(t, "dir")
run.mkdir(t, "dir1")
run.checkDir(t, "dir/|dir1/")
@@ -94,6 +104,8 @@ func TestDirRenameEmptyDir(t *testing.T) {
}
func TestDirRenameFullDir(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
run.mkdir(t, "dir")
run.mkdir(t, "dir1")
run.createFile(t, "dir1/potato.txt", "maris piper")
diff --git a/cmd/mount/fs_test.go b/cmd/mount/fs_test.go
index 2c589800e..c1f1fae5a 100644
--- a/cmd/mount/fs_test.go
+++ b/cmd/mount/fs_test.go
@@ -49,6 +49,7 @@ type Run struct {
fremoteName string
cleanRemote func()
umountResult <-chan error
+ skip bool
}
// run holds the master Run data
@@ -97,12 +98,17 @@ func (r *Run) mount() {
var err error
r.umountResult, err = mount(r.fremote, r.mountPath)
if err != nil {
- log.Fatalf("umount failed: %v", err)
+ log.Printf("mount failed: %v", err)
+ r.skip = true
}
log.Printf("mount OK")
}
func (r *Run) umount() {
+ if r.skip {
+ log.Printf("FUSE not found so skipping umount")
+ return
+ }
log.Printf("Calling fusermount -u %q", r.mountPath)
err := exec.Command("fusermount", "-u", r.mountPath).Run()
if err != nil {
@@ -115,6 +121,12 @@ func (r *Run) umount() {
}
}
+func (r *Run) skipIfNoFUSE(t *testing.T) {
+ if r.skip {
+ t.Skip("FUSE not found so skipping test")
+ }
+}
+
// Finalise cleans the remote and unmounts
func (r *Run) Finalise() {
r.umount()
@@ -234,6 +246,8 @@ func (r *Run) rmdir(t *testing.T, filepath string) {
// Check that the Fs is mounted by seeing if the mountpoint is
// in the mount output
func TestMount(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
out, err := exec.Command("mount").Output()
require.NoError(t, err)
assert.Contains(t, string(out), run.mountPath)
@@ -241,6 +255,8 @@ func TestMount(t *testing.T) {
// Check root directory is present and correct
func TestRoot(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
fi, err := os.Lstat(run.mountPath)
require.NoError(t, err)
assert.True(t, fi.IsDir())
diff --git a/cmd/mount/read_test.go b/cmd/mount/read_test.go
index 7afb79965..7b385afd4 100644
--- a/cmd/mount/read_test.go
+++ b/cmd/mount/read_test.go
@@ -13,6 +13,8 @@ import (
// Read by byte including don't read any bytes
func TestReadByByte(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
var data = []byte("hellohello")
run.createFile(t, "testfile", string(data))
run.checkDir(t, "testfile 10")
@@ -36,6 +38,8 @@ func TestReadByByte(t *testing.T) {
// Test double close
func TestReadFileDoubleClose(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
run.createFile(t, "testdoubleclose", "hello")
in, err := os.Open(run.path("testdoubleclose"))
diff --git a/cmd/mount/write_test.go b/cmd/mount/write_test.go
index c94bb7f96..7c3d5c388 100644
--- a/cmd/mount/write_test.go
+++ b/cmd/mount/write_test.go
@@ -12,6 +12,8 @@ import (
// Test writing a file with no write()'s to it
func TestWriteFileNoWrite(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
fd, err := os.Create(run.path("testnowrite"))
assert.NoError(t, err)
@@ -25,6 +27,8 @@ func TestWriteFileNoWrite(t *testing.T) {
// Test open file in directory listing
func FIXMETestWriteOpenFileInDirListing(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
fd, err := os.Create(run.path("testnowrite"))
assert.NoError(t, err)
@@ -38,6 +42,8 @@ func FIXMETestWriteOpenFileInDirListing(t *testing.T) {
// Test writing a file and reading it back
func TestWriteFileWrite(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
run.createFile(t, "testwrite", "data")
run.checkDir(t, "testwrite 4")
contents := run.readFile(t, "testwrite")
@@ -47,6 +53,8 @@ func TestWriteFileWrite(t *testing.T) {
// Test overwriting a file
func TestWriteFileOverwrite(t *testing.T) {
+ run.skipIfNoFUSE(t)
+
run.createFile(t, "testwrite", "data")
run.checkDir(t, "testwrite 4")
run.createFile(t, "testwrite", "potato")
@@ -57,6 +65,8 @@ func TestWriteFileOverwrite(t *testing.T) {
// 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()