Skip tests if test remote not configured

This commit is contained in:
Nick Craig-Wood 2014-07-31 08:51:39 +01:00
parent c389616657
commit ff91698fb5
4 changed files with 22 additions and 15 deletions

View File

@ -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)

View File

@ -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) {

View File

@ -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)
}

View File

@ -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)