Skip tests if test remote not configured
This commit is contained in:
parent
c389616657
commit
ff91698fb5
4 changed files with 22 additions and 15 deletions
4
fs/fs.go
4
fs/fs.go
|
@ -20,6 +20,8 @@ const (
|
||||||
var (
|
var (
|
||||||
// Filesystem registry
|
// Filesystem registry
|
||||||
fsRegistry []*FsInfo
|
fsRegistry []*FsInfo
|
||||||
|
// Error returned by NewFs if not found in config file
|
||||||
|
NotFoundInConfigFile = fmt.Errorf("Didn't find section in config file")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Filesystem info
|
// Filesystem info
|
||||||
|
@ -193,7 +195,7 @@ func NewFs(path string) (Fs, error) {
|
||||||
var err error
|
var err error
|
||||||
fsName, err = ConfigFile.GetValue(configName, "type")
|
fsName, err = ConfigFile.GetValue(configName, "type")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Didn't find section in config file for %q", configName)
|
return nil, NotFoundInConfigFile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fs, err := Find(fsName)
|
fs, err := Find(fsName)
|
||||||
|
|
|
@ -129,14 +129,14 @@ func RandomString(n int) string {
|
||||||
//
|
//
|
||||||
// Call the finalise function returned to Purge the fs at the end (and
|
// Call the finalise function returned to Purge the fs at the end (and
|
||||||
// the parent if necessary)
|
// 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
|
// Make a directory if remote name is null
|
||||||
rmdir := ""
|
rmdir := ""
|
||||||
var err error
|
var err error
|
||||||
if remoteName == "" {
|
if remoteName == "" {
|
||||||
remoteName, err = ioutil.TempDir("", "rclone")
|
remoteName, err = ioutil.TempDir("", "rclone")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("Failed to create temp dir: %v", err)
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
rmdir = remoteName
|
rmdir = remoteName
|
||||||
}
|
}
|
||||||
|
@ -150,14 +150,14 @@ func RandomRemote(remoteName string, subdir bool) (fs.Fs, func()) {
|
||||||
var err error
|
var err error
|
||||||
parentRemote, err = fs.NewFs(remoteName)
|
parentRemote, err = fs.NewFs(remoteName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to make parent %q: %v", remoteName, err)
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
remoteName += "/" + RandomString(8)
|
remoteName += "/" + RandomString(8)
|
||||||
}
|
}
|
||||||
|
|
||||||
remote, err := fs.NewFs(remoteName)
|
remote, err := fs.NewFs(remoteName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to make %q: %v", remoteName, err)
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
finalise := func() {
|
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) {
|
func TestMkdir(remote fs.Fs) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -34,13 +35,15 @@ func TestInit(t *testing.T) {
|
||||||
fs.LoadConfig()
|
fs.LoadConfig()
|
||||||
fs.Config.Verbose = false
|
fs.Config.Verbose = false
|
||||||
fs.Config.Quiet = true
|
fs.Config.Quiet = true
|
||||||
remote, remoteFinalise = fstest.RandomRemote(RemoteName, false)
|
var err error
|
||||||
// if err != nil {
|
remote, remoteFinalise, err = fstest.RandomRemote(RemoteName, false)
|
||||||
// if strings.Contains(err.Error(), "Didn't find section in config file") {
|
if err == fs.NotFoundInConfigFile {
|
||||||
// return
|
log.Printf("Didn't find %q in config file - skipping tests", RemoteName)
|
||||||
// }
|
return
|
||||||
// t.Fatalf("Couldn't start FS: %v", err)
|
}
|
||||||
// }
|
if err != nil {
|
||||||
|
t.Fatalf("Couldn't start FS: %v", err)
|
||||||
|
}
|
||||||
fstest.Fatalf = t.Fatalf
|
fstest.Fatalf = t.Fatalf
|
||||||
fstest.TestMkdir(remote)
|
fstest.TestMkdir(remote)
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,10 +257,12 @@ func main() {
|
||||||
os.Exit(1)
|
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)
|
log.Printf("Testing with remote %v", fremote)
|
||||||
|
|
||||||
var err error
|
|
||||||
localName, err = ioutil.TempDir("", "rclone")
|
localName, err = ioutil.TempDir("", "rclone")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to create temp dir: %v", err)
|
log.Fatalf("Failed to create temp dir: %v", err)
|
||||||
|
|
Loading…
Reference in a new issue