mirror of
https://github.com/rclone/rclone.git
synced 2025-02-02 03:29:51 +01:00
mounttest: fixes for running under Windows
* don't mount and unmount between cache runs - WinFSP doesn't suport it * use OS paths for opening things
This commit is contained in:
parent
9738f8532b
commit
9fbd8a6419
@ -10,6 +10,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -20,7 +21,6 @@ import (
|
|||||||
_ "github.com/ncw/rclone/fs/all" // import all the file systems
|
_ "github.com/ncw/rclone/fs/all" // import all the file systems
|
||||||
"github.com/ncw/rclone/fstest"
|
"github.com/ncw/rclone/fstest"
|
||||||
"github.com/ncw/rclone/vfs"
|
"github.com/ncw/rclone/vfs"
|
||||||
"github.com/ncw/rclone/vfs/vfsflags"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@ -47,18 +47,17 @@ func TestMain(m *testing.M, fn MountFn) {
|
|||||||
vfs.CacheModeWrites,
|
vfs.CacheModeWrites,
|
||||||
vfs.CacheModeFull,
|
vfs.CacheModeFull,
|
||||||
}
|
}
|
||||||
|
run = newRun()
|
||||||
for _, cacheMode := range cacheModes {
|
for _, cacheMode := range cacheModes {
|
||||||
vfsflags.Opt.CacheMode = cacheMode
|
run.cacheMode(cacheMode)
|
||||||
log.Printf("Starting test run with cache mode %v", cacheMode)
|
log.Printf("Starting test run with cache mode %v", cacheMode)
|
||||||
run = newRun()
|
|
||||||
rc = m.Run()
|
rc = m.Run()
|
||||||
run.Finalise()
|
|
||||||
log.Printf("Finished test run with cache mode %v", cacheMode)
|
log.Printf("Finished test run with cache mode %v", cacheMode)
|
||||||
if rc != 0 {
|
if rc != 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vfsflags.Opt.CacheMode = vfs.DefaultOpt.CacheMode
|
run.Finalise()
|
||||||
os.Exit(rc)
|
os.Exit(rc)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,6 +172,28 @@ func (r *Run) umount() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cacheMode flushes the VFS and changes the CacheMode
|
||||||
|
func (r *Run) cacheMode(cacheMode vfs.CacheMode) {
|
||||||
|
// Wait for writers to finish
|
||||||
|
r.vfs.WaitForWriters(30 * time.Second)
|
||||||
|
// Empty and remake the remote
|
||||||
|
r.cleanRemote()
|
||||||
|
err := r.fremote.Mkdir("")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to open mkdir %q: %v", *fstest.RemoteName, err)
|
||||||
|
}
|
||||||
|
// Empty the cache
|
||||||
|
err = r.vfs.CleanUp()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to cleanup the VFS cache: %v", err)
|
||||||
|
}
|
||||||
|
// Reset the cache mode
|
||||||
|
r.vfs.Opt.CacheMode = cacheMode
|
||||||
|
// Flush the directory cache
|
||||||
|
r.vfs.FlushDirCache()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Run) skipIfNoFUSE(t *testing.T) {
|
func (r *Run) skipIfNoFUSE(t *testing.T) {
|
||||||
if r.skip {
|
if r.skip {
|
||||||
t.Skip("FUSE not found so skipping test")
|
t.Skip("FUSE not found so skipping test")
|
||||||
@ -189,12 +210,13 @@ func (r *Run) Finalise() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Run) path(filepath string) string {
|
// path returns an OS local path for filepath
|
||||||
// return windows drive letter root as E:/
|
func (r *Run) path(filePath string) string {
|
||||||
if filepath == "" && runtime.GOOS == "windows" {
|
// return windows drive letter root as E:\
|
||||||
return run.mountPath + "/"
|
if filePath == "" && runtime.GOOS == "windows" {
|
||||||
|
return run.mountPath + `\`
|
||||||
}
|
}
|
||||||
return path.Join(run.mountPath, filepath)
|
return filepath.Join(run.mountPath, filepath.FromSlash(filePath))
|
||||||
}
|
}
|
||||||
|
|
||||||
type dirMap map[string]struct{}
|
type dirMap map[string]struct{}
|
||||||
@ -222,12 +244,12 @@ func (dm dirMap) filesOnly() dirMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// reads the local tree into dir
|
// reads the local tree into dir
|
||||||
func (r *Run) readLocal(t *testing.T, dir dirMap, filepath string) {
|
func (r *Run) readLocal(t *testing.T, dir dirMap, filePath string) {
|
||||||
realPath := r.path(filepath)
|
realPath := r.path(filePath)
|
||||||
files, err := ioutil.ReadDir(realPath)
|
files, err := ioutil.ReadDir(realPath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
for _, fi := range files {
|
for _, fi := range files {
|
||||||
name := path.Join(filepath, fi.Name())
|
name := path.Join(filePath, fi.Name())
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
dir[name+"/"] = struct{}{}
|
dir[name+"/"] = struct{}{}
|
||||||
r.readLocal(t, dir, name)
|
r.readLocal(t, dir, name)
|
||||||
@ -259,13 +281,14 @@ func (r *Run) readRemote(t *testing.T, dir dirMap, filepath string) {
|
|||||||
// checkDir checks the local and remote against the string passed in
|
// checkDir checks the local and remote against the string passed in
|
||||||
func (r *Run) checkDir(t *testing.T, dirString string) {
|
func (r *Run) checkDir(t *testing.T, dirString string) {
|
||||||
var retries = *fstest.ListRetries
|
var retries = *fstest.ListRetries
|
||||||
sleep := time.Second / 2
|
sleep := time.Second / 5
|
||||||
var remoteOK, fuseOK bool
|
var remoteOK, fuseOK bool
|
||||||
|
var dm, localDm, remoteDm dirMap
|
||||||
for i := 1; i <= retries; i++ {
|
for i := 1; i <= retries; i++ {
|
||||||
dm := newDirMap(dirString)
|
dm = newDirMap(dirString)
|
||||||
localDm := make(dirMap)
|
localDm = make(dirMap)
|
||||||
r.readLocal(t, localDm, "")
|
r.readLocal(t, localDm, "")
|
||||||
remoteDm := make(dirMap)
|
remoteDm = make(dirMap)
|
||||||
r.readRemote(t, remoteDm, "")
|
r.readRemote(t, remoteDm, "")
|
||||||
// Ignore directories for remote compare
|
// Ignore directories for remote compare
|
||||||
remoteOK = reflect.DeepEqual(dm.filesOnly(), remoteDm.filesOnly())
|
remoteOK = reflect.DeepEqual(dm.filesOnly(), remoteDm.filesOnly())
|
||||||
@ -277,8 +300,8 @@ func (r *Run) checkDir(t *testing.T, dirString string) {
|
|||||||
t.Logf("Sleeping for %v for list eventual consistency: %d/%d", sleep, i, retries)
|
t.Logf("Sleeping for %v for list eventual consistency: %d/%d", sleep, i, retries)
|
||||||
time.Sleep(sleep)
|
time.Sleep(sleep)
|
||||||
}
|
}
|
||||||
assert.True(t, remoteOK, "expected vs remote")
|
assert.Equal(t, dm.filesOnly(), remoteDm.filesOnly(), "expected vs remote")
|
||||||
assert.True(t, fuseOK, "expected vs fuse mount")
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Run) createFile(t *testing.T, filepath string, contents string) {
|
func (r *Run) createFile(t *testing.T, filepath string, contents string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user