diff --git a/fs/fs.go b/fs/fs.go index 6382a4b07..489c4aeb7 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -20,6 +20,8 @@ const ( var ( // Filesystem registry fsRegistry []*FsInfo + // Error returned by NewFs if not found in config file + NotFoundInConfigFile = fmt.Errorf("Didn't find section in config file") ) // Filesystem info @@ -193,7 +195,7 @@ func NewFs(path string) (Fs, error) { var err error fsName, err = ConfigFile.GetValue(configName, "type") if err != nil { - return nil, fmt.Errorf("Didn't find section in config file for %q", configName) + return nil, NotFoundInConfigFile } } fs, err := Find(fsName) diff --git a/fstest/fstest.go b/fstest/fstest.go index 2e35036e2..c3c2e77cf 100644 --- a/fstest/fstest.go +++ b/fstest/fstest.go @@ -129,14 +129,14 @@ func RandomString(n int) string { // // Call the finalise function returned to Purge the fs at the end (and // the parent if necessary) -func RandomRemote(remoteName string, subdir bool) (fs.Fs, func()) { +func RandomRemote(remoteName string, subdir bool) (fs.Fs, func(), error) { // Make a directory if remote name is null rmdir := "" var err error if remoteName == "" { remoteName, err = ioutil.TempDir("", "rclone") if err != nil { - Fatalf("Failed to create temp dir: %v", err) + return nil, nil, err } rmdir = remoteName } @@ -150,14 +150,14 @@ func RandomRemote(remoteName string, subdir bool) (fs.Fs, func()) { var err error parentRemote, err = fs.NewFs(remoteName) if err != nil { - log.Fatalf("Failed to make parent %q: %v", remoteName, err) + return nil, nil, err } remoteName += "/" + RandomString(8) } remote, err := fs.NewFs(remoteName) if err != nil { - log.Fatalf("Failed to make %q: %v", remoteName, err) + return nil, nil, err } finalise := func() { @@ -177,7 +177,7 @@ func RandomRemote(remoteName string, subdir bool) (fs.Fs, func()) { } } - return remote, finalise + return remote, finalise, nil } func TestMkdir(remote fs.Fs) { diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go index b7d3ca337..7e0968025 100644 --- a/fstest/fstests/fstests.go +++ b/fstest/fstests/fstests.go @@ -8,6 +8,7 @@ import ( "crypto/md5" "encoding/hex" "io" + "log" "testing" "time" @@ -34,13 +35,15 @@ func TestInit(t *testing.T) { fs.LoadConfig() fs.Config.Verbose = false fs.Config.Quiet = true - remote, remoteFinalise = fstest.RandomRemote(RemoteName, false) - // if err != nil { - // if strings.Contains(err.Error(), "Didn't find section in config file") { - // return - // } - // t.Fatalf("Couldn't start FS: %v", err) - // } + var err error + remote, remoteFinalise, err = fstest.RandomRemote(RemoteName, false) + if err == fs.NotFoundInConfigFile { + log.Printf("Didn't find %q in config file - skipping tests", RemoteName) + return + } + if err != nil { + t.Fatalf("Couldn't start FS: %v", err) + } fstest.Fatalf = t.Fatalf fstest.TestMkdir(remote) } diff --git a/rclonetest/rclonetest.go b/rclonetest/rclonetest.go index 2a94f3eea..2876b19af 100644 --- a/rclonetest/rclonetest.go +++ b/rclonetest/rclonetest.go @@ -257,10 +257,12 @@ func main() { os.Exit(1) } - fremote, finalise := fstest.RandomRemote(args[0], *subDir) + fremote, finalise, err := fstest.RandomRemote(args[0], *subDir) + if err != nil { + log.Fatalf("Failed to open remote %q: %v", args[0], err) + } log.Printf("Testing with remote %v", fremote) - var err error localName, err = ioutil.TempDir("", "rclone") if err != nil { log.Fatalf("Failed to create temp dir: %v", err)