mirror of
https://github.com/rclone/rclone.git
synced 2025-12-16 00:04:40 +00:00
fstest: Factor test initialisation into Initialise()
This commit is contained in:
@@ -24,11 +24,20 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// Globals
|
||||
var (
|
||||
// MatchTestRemote matches the remote names used for testing
|
||||
MatchTestRemote = regexp.MustCompile(`^rclone-test-[abcdefghijklmnopqrstuvwxyz0123456789]{24}$`)
|
||||
RemoteName = flag.String("remote", "", "Remote to test with, defaults to local filesystem")
|
||||
SubDir = flag.Bool("subdir", false, "Set to test with a sub directory")
|
||||
Verbose = flag.Bool("verbose", false, "Set to enable logging")
|
||||
DumpHeaders = flag.Bool("dump-headers", false, "Set to dump headers (needs -verbose)")
|
||||
DumpBodies = flag.Bool("dump-bodies", false, "Set to dump bodies (needs -verbose)")
|
||||
Individual = flag.Bool("individual", false, "Make individual bucket/container/directory for each test - much slower")
|
||||
LowLevelRetries = flag.Int("low-level-retries", 10, "Number of low level retries")
|
||||
UseListR = flag.Bool("fast-list", false, "Use recursive list if available. Uses more memory but fewer transactions.")
|
||||
// ListRetries is the number of times to retry a listing to overcome eventual consistency
|
||||
ListRetries = flag.Int("list-retries", 6, "Number or times to retry listing")
|
||||
// MatchTestRemote matches the remote names used for testing
|
||||
MatchTestRemote = regexp.MustCompile(`^rclone-test-[abcdefghijklmnopqrstuvwxyz0123456789]{24}$`)
|
||||
)
|
||||
|
||||
// Seed the random number generator
|
||||
@@ -37,6 +46,22 @@ func init() {
|
||||
|
||||
}
|
||||
|
||||
// Initialise rclone for testing
|
||||
func Initialise() {
|
||||
// Never ask for passwords, fail instead.
|
||||
// If your local config is encrypted set environment variable
|
||||
// "RCLONE_CONFIG_PASS=hunter2" (or your password)
|
||||
*fs.AskPassword = false
|
||||
fs.LoadConfig()
|
||||
if *Verbose {
|
||||
fs.Config.LogLevel = fs.LogLevelDebug
|
||||
}
|
||||
fs.Config.DumpHeaders = *DumpHeaders
|
||||
fs.Config.DumpBodies = *DumpBodies
|
||||
fs.Config.LowLevelRetries = *LowLevelRetries
|
||||
fs.Config.UseListR = *UseListR
|
||||
}
|
||||
|
||||
// Item represents an item for checking
|
||||
type Item struct {
|
||||
Path string
|
||||
|
||||
@@ -7,7 +7,6 @@ package fstests
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -48,12 +47,8 @@ var (
|
||||
Path: `hello? sausage/êé/Hello, 世界/ " ' @ < > & ? + ≠/z.txt`,
|
||||
WinPath: `hello_ sausage/êé/Hello, 世界/ _ ' @ _ _ & _ + ≠/z.txt`,
|
||||
}
|
||||
file2Contents = ""
|
||||
verbose = flag.Bool("verbose", false, "Set to enable logging")
|
||||
dumpHeaders = flag.Bool("dump-headers", false, "Dump HTTP headers - may contain sensitive info")
|
||||
dumpBodies = flag.Bool("dump-bodies", false, "Dump HTTP headers and bodies - may contain sensitive info")
|
||||
overrideRemote = flag.String("remote", "", "Set this to override the default remote name (eg s3:)")
|
||||
isLocalRemote bool
|
||||
file2Contents = ""
|
||||
isLocalRemote bool
|
||||
)
|
||||
|
||||
// ExtraConfigItem describes a config item added on the fly while testing
|
||||
@@ -69,22 +64,14 @@ func TestInit(t *testing.T) {
|
||||
file2.Path = winPath(file2.Path)
|
||||
}
|
||||
|
||||
// Never ask for passwords, fail instead.
|
||||
// If your local config is encrypted set environment variable
|
||||
// "RCLONE_CONFIG_PASS=hunter2" (or your password)
|
||||
*fs.AskPassword = false
|
||||
fs.LoadConfig()
|
||||
fstest.Initialise()
|
||||
|
||||
// Set extra config if supplied
|
||||
for _, item := range ExtraConfig {
|
||||
fs.ConfigFileSet(item.Name, item.Key, item.Value)
|
||||
}
|
||||
if *verbose {
|
||||
fs.Config.LogLevel = fs.LogLevelDebug
|
||||
}
|
||||
fs.Config.DumpHeaders = *dumpHeaders
|
||||
fs.Config.DumpBodies = *dumpBodies
|
||||
if *overrideRemote != "" {
|
||||
RemoteName = *overrideRemote
|
||||
if *fstest.RemoteName != "" {
|
||||
RemoteName = *fstest.RemoteName
|
||||
}
|
||||
t.Logf("Using remote %q", RemoteName)
|
||||
if RemoteName == "" {
|
||||
|
||||
Reference in New Issue
Block a user