Fix tests when FUSE isn't present

This commit is contained in:
Nick Craig-Wood 2016-08-20 12:43:33 +01:00
parent 6089f443b9
commit 9e7ddd5efc
4 changed files with 43 additions and 1 deletions

View file

@ -11,6 +11,8 @@ import (
) )
func TestDirLs(t *testing.T) { func TestDirLs(t *testing.T) {
run.skipIfNoFUSE(t)
run.checkDir(t, "") run.checkDir(t, "")
run.mkdir(t, "a directory") run.mkdir(t, "a directory")
@ -25,6 +27,8 @@ func TestDirLs(t *testing.T) {
} }
func TestDirCreateAndRemoveDir(t *testing.T) { func TestDirCreateAndRemoveDir(t *testing.T) {
run.skipIfNoFUSE(t)
run.mkdir(t, "dir") run.mkdir(t, "dir")
run.mkdir(t, "dir/subdir") run.mkdir(t, "dir/subdir")
run.checkDir(t, "dir/|dir/subdir/") run.checkDir(t, "dir/|dir/subdir/")
@ -41,6 +45,8 @@ func TestDirCreateAndRemoveDir(t *testing.T) {
} }
func TestDirCreateAndRemoveFile(t *testing.T) { func TestDirCreateAndRemoveFile(t *testing.T) {
run.skipIfNoFUSE(t)
run.mkdir(t, "dir") run.mkdir(t, "dir")
run.createFile(t, "dir/file", "potato") run.createFile(t, "dir/file", "potato")
run.checkDir(t, "dir/|dir/file 6") run.checkDir(t, "dir/|dir/file 6")
@ -58,6 +64,8 @@ func TestDirCreateAndRemoveFile(t *testing.T) {
} }
func TestDirRenameFile(t *testing.T) { func TestDirRenameFile(t *testing.T) {
run.skipIfNoFUSE(t)
run.mkdir(t, "dir") run.mkdir(t, "dir")
run.createFile(t, "file", "potato") run.createFile(t, "file", "potato")
run.checkDir(t, "dir/|file 6") run.checkDir(t, "dir/|file 6")
@ -76,6 +84,8 @@ func TestDirRenameFile(t *testing.T) {
} }
func TestDirRenameEmptyDir(t *testing.T) { func TestDirRenameEmptyDir(t *testing.T) {
run.skipIfNoFUSE(t)
run.mkdir(t, "dir") run.mkdir(t, "dir")
run.mkdir(t, "dir1") run.mkdir(t, "dir1")
run.checkDir(t, "dir/|dir1/") run.checkDir(t, "dir/|dir1/")
@ -94,6 +104,8 @@ func TestDirRenameEmptyDir(t *testing.T) {
} }
func TestDirRenameFullDir(t *testing.T) { func TestDirRenameFullDir(t *testing.T) {
run.skipIfNoFUSE(t)
run.mkdir(t, "dir") run.mkdir(t, "dir")
run.mkdir(t, "dir1") run.mkdir(t, "dir1")
run.createFile(t, "dir1/potato.txt", "maris piper") run.createFile(t, "dir1/potato.txt", "maris piper")

View file

@ -49,6 +49,7 @@ type Run struct {
fremoteName string fremoteName string
cleanRemote func() cleanRemote func()
umountResult <-chan error umountResult <-chan error
skip bool
} }
// run holds the master Run data // run holds the master Run data
@ -97,12 +98,17 @@ func (r *Run) mount() {
var err error var err error
r.umountResult, err = mount(r.fremote, r.mountPath) r.umountResult, err = mount(r.fremote, r.mountPath)
if err != nil { if err != nil {
log.Fatalf("umount failed: %v", err) log.Printf("mount failed: %v", err)
r.skip = true
} }
log.Printf("mount OK") log.Printf("mount OK")
} }
func (r *Run) umount() { func (r *Run) umount() {
if r.skip {
log.Printf("FUSE not found so skipping umount")
return
}
log.Printf("Calling fusermount -u %q", r.mountPath) log.Printf("Calling fusermount -u %q", r.mountPath)
err := exec.Command("fusermount", "-u", r.mountPath).Run() err := exec.Command("fusermount", "-u", r.mountPath).Run()
if err != nil { 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 // Finalise cleans the remote and unmounts
func (r *Run) Finalise() { func (r *Run) Finalise() {
r.umount() 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 // Check that the Fs is mounted by seeing if the mountpoint is
// in the mount output // in the mount output
func TestMount(t *testing.T) { func TestMount(t *testing.T) {
run.skipIfNoFUSE(t)
out, err := exec.Command("mount").Output() out, err := exec.Command("mount").Output()
require.NoError(t, err) require.NoError(t, err)
assert.Contains(t, string(out), run.mountPath) assert.Contains(t, string(out), run.mountPath)
@ -241,6 +255,8 @@ func TestMount(t *testing.T) {
// Check root directory is present and correct // Check root directory is present and correct
func TestRoot(t *testing.T) { func TestRoot(t *testing.T) {
run.skipIfNoFUSE(t)
fi, err := os.Lstat(run.mountPath) fi, err := os.Lstat(run.mountPath)
require.NoError(t, err) require.NoError(t, err)
assert.True(t, fi.IsDir()) assert.True(t, fi.IsDir())

View file

@ -13,6 +13,8 @@ import (
// Read by byte including don't read any bytes // Read by byte including don't read any bytes
func TestReadByByte(t *testing.T) { func TestReadByByte(t *testing.T) {
run.skipIfNoFUSE(t)
var data = []byte("hellohello") var data = []byte("hellohello")
run.createFile(t, "testfile", string(data)) run.createFile(t, "testfile", string(data))
run.checkDir(t, "testfile 10") run.checkDir(t, "testfile 10")
@ -36,6 +38,8 @@ func TestReadByByte(t *testing.T) {
// Test double close // Test double close
func TestReadFileDoubleClose(t *testing.T) { func TestReadFileDoubleClose(t *testing.T) {
run.skipIfNoFUSE(t)
run.createFile(t, "testdoubleclose", "hello") run.createFile(t, "testdoubleclose", "hello")
in, err := os.Open(run.path("testdoubleclose")) in, err := os.Open(run.path("testdoubleclose"))

View file

@ -12,6 +12,8 @@ import (
// Test writing a file with no write()'s to it // Test writing a file with no write()'s to it
func TestWriteFileNoWrite(t *testing.T) { func TestWriteFileNoWrite(t *testing.T) {
run.skipIfNoFUSE(t)
fd, err := os.Create(run.path("testnowrite")) fd, err := os.Create(run.path("testnowrite"))
assert.NoError(t, err) assert.NoError(t, err)
@ -25,6 +27,8 @@ func TestWriteFileNoWrite(t *testing.T) {
// Test open file in directory listing // Test open file in directory listing
func FIXMETestWriteOpenFileInDirListing(t *testing.T) { func FIXMETestWriteOpenFileInDirListing(t *testing.T) {
run.skipIfNoFUSE(t)
fd, err := os.Create(run.path("testnowrite")) fd, err := os.Create(run.path("testnowrite"))
assert.NoError(t, err) assert.NoError(t, err)
@ -38,6 +42,8 @@ func FIXMETestWriteOpenFileInDirListing(t *testing.T) {
// Test writing a file and reading it back // Test writing a file and reading it back
func TestWriteFileWrite(t *testing.T) { func TestWriteFileWrite(t *testing.T) {
run.skipIfNoFUSE(t)
run.createFile(t, "testwrite", "data") run.createFile(t, "testwrite", "data")
run.checkDir(t, "testwrite 4") run.checkDir(t, "testwrite 4")
contents := run.readFile(t, "testwrite") contents := run.readFile(t, "testwrite")
@ -47,6 +53,8 @@ func TestWriteFileWrite(t *testing.T) {
// Test overwriting a file // Test overwriting a file
func TestWriteFileOverwrite(t *testing.T) { func TestWriteFileOverwrite(t *testing.T) {
run.skipIfNoFUSE(t)
run.createFile(t, "testwrite", "data") run.createFile(t, "testwrite", "data")
run.checkDir(t, "testwrite 4") run.checkDir(t, "testwrite 4")
run.createFile(t, "testwrite", "potato") run.createFile(t, "testwrite", "potato")
@ -57,6 +65,8 @@ func TestWriteFileOverwrite(t *testing.T) {
// Test double close // Test double close
func TestWriteFileDoubleClose(t *testing.T) { func TestWriteFileDoubleClose(t *testing.T) {
run.skipIfNoFUSE(t)
out, err := os.Create(run.path("testdoubleclose")) out, err := os.Create(run.path("testdoubleclose"))
assert.NoError(t, err) assert.NoError(t, err)
fd := out.Fd() fd := out.Fd()