mirror of
https://github.com/rclone/rclone.git
synced 2025-01-10 00:08:44 +01:00
fstest: Factor test initialisation into Initialise()
This commit is contained in:
parent
1ecf2bcbd5
commit
cd4895690a
@ -23,17 +23,6 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Globals
|
|
||||||
var (
|
|
||||||
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")
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// UnmountFn is called to unmount the file system
|
// UnmountFn is called to unmount the file system
|
||||||
UnmountFn func() error
|
UnmountFn func() error
|
||||||
@ -81,26 +70,17 @@ func newRun() *Run {
|
|||||||
umountResult: make(chan error, 1),
|
umountResult: make(chan error, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never ask for passwords, fail instead.
|
fstest.Initialise()
|
||||||
// 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
|
|
||||||
var err error
|
var err error
|
||||||
r.fremote, r.fremoteName, r.cleanRemote, err = fstest.RandomRemote(*RemoteName, *SubDir)
|
r.fremote, r.fremoteName, r.cleanRemote, err = fstest.RandomRemote(*fstest.RemoteName, *fstest.SubDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to open remote %q: %v", *RemoteName, err)
|
log.Fatalf("Failed to open remote %q: %v", *fstest.RemoteName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = r.fremote.Mkdir("")
|
err = r.fremote.Mkdir("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to open mkdir %q: %v", *RemoteName, err)
|
log.Fatalf("Failed to open mkdir %q: %v", *fstest.RemoteName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS != "windows" {
|
||||||
|
@ -43,18 +43,6 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Globals
|
|
||||||
var (
|
|
||||||
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.")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Some times used in the tests
|
// Some times used in the tests
|
||||||
var (
|
var (
|
||||||
t1 = fstest.Time("2001-02-03T04:05:06.499999999Z")
|
t1 = fstest.Time("2001-02-03T04:05:06.499999999Z")
|
||||||
@ -65,11 +53,11 @@ var (
|
|||||||
// TestMain drives the tests
|
// TestMain drives the tests
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if !*Individual {
|
if !*fstest.Individual {
|
||||||
oneRun = newRun()
|
oneRun = newRun()
|
||||||
}
|
}
|
||||||
rc := m.Run()
|
rc := m.Run()
|
||||||
if !*Individual {
|
if !*fstest.Individual {
|
||||||
oneRun.Finalise()
|
oneRun.Finalise()
|
||||||
}
|
}
|
||||||
os.Exit(rc)
|
os.Exit(rc)
|
||||||
@ -103,22 +91,12 @@ func newRun() *Run {
|
|||||||
mkdir: make(map[string]bool),
|
mkdir: make(map[string]bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never ask for passwords, fail instead.
|
fstest.Initialise()
|
||||||
// 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
|
|
||||||
var err error
|
var err error
|
||||||
r.fremote, r.fremoteName, r.cleanRemote, err = fstest.RandomRemote(*RemoteName, *SubDir)
|
r.fremote, r.fremoteName, r.cleanRemote, err = fstest.RandomRemote(*fstest.RemoteName, *fstest.SubDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.Fatalf("Failed to open remote %q: %v", *RemoteName, err)
|
r.Fatalf("Failed to open remote %q: %v", *fstest.RemoteName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
r.localName, err = ioutil.TempDir("", "rclone")
|
r.localName, err = ioutil.TempDir("", "rclone")
|
||||||
@ -150,7 +128,7 @@ func (d dirsToRemove) Less(i, j int) bool { return len(d[i]) > len(d[j]) }
|
|||||||
// Finalise() will tidy them away when done.
|
// Finalise() will tidy them away when done.
|
||||||
func NewRun(t *testing.T) *Run {
|
func NewRun(t *testing.T) *Run {
|
||||||
var r *Run
|
var r *Run
|
||||||
if *Individual {
|
if *fstest.Individual {
|
||||||
r = newRun()
|
r = newRun()
|
||||||
} else {
|
} else {
|
||||||
// If not individual, use the global one with the clean method overridden
|
// If not individual, use the global one with the clean method overridden
|
||||||
|
@ -102,7 +102,7 @@ func TestServerSideCopy(t *testing.T) {
|
|||||||
file1 := r.WriteObject("sub dir/hello world", "hello world", t1)
|
file1 := r.WriteObject("sub dir/hello world", "hello world", t1)
|
||||||
fstest.CheckItems(t, r.fremote, file1)
|
fstest.CheckItems(t, r.fremote, file1)
|
||||||
|
|
||||||
fremoteCopy, _, finaliseCopy, err := fstest.RandomRemote(*RemoteName, *SubDir)
|
fremoteCopy, _, finaliseCopy, err := fstest.RandomRemote(*fstest.RemoteName, *fstest.SubDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer finaliseCopy()
|
defer finaliseCopy()
|
||||||
t.Logf("Server side copy (if possible) %v -> %v", r.fremote, fremoteCopy)
|
t.Logf("Server side copy (if possible) %v -> %v", r.fremote, fremoteCopy)
|
||||||
@ -735,7 +735,7 @@ func testServerSideMove(t *testing.T, r *Run, fremoteMove fs.Fs, withFilter bool
|
|||||||
func TestServerSideMove(t *testing.T) {
|
func TestServerSideMove(t *testing.T) {
|
||||||
r := NewRun(t)
|
r := NewRun(t)
|
||||||
defer r.Finalise()
|
defer r.Finalise()
|
||||||
fremoteMove, _, finaliseMove, err := fstest.RandomRemote(*RemoteName, *SubDir)
|
fremoteMove, _, finaliseMove, err := fstest.RandomRemote(*fstest.RemoteName, *fstest.SubDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer finaliseMove()
|
defer finaliseMove()
|
||||||
testServerSideMove(t, r, fremoteMove, false)
|
testServerSideMove(t, r, fremoteMove, false)
|
||||||
@ -751,7 +751,7 @@ func TestServerSideMoveWithFilter(t *testing.T) {
|
|||||||
fs.Config.Filter.MinSize = -1
|
fs.Config.Filter.MinSize = -1
|
||||||
}()
|
}()
|
||||||
|
|
||||||
fremoteMove, _, finaliseMove, err := fstest.RandomRemote(*RemoteName, *SubDir)
|
fremoteMove, _, finaliseMove, err := fstest.RandomRemote(*fstest.RemoteName, *fstest.SubDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer finaliseMove()
|
defer finaliseMove()
|
||||||
testServerSideMove(t, r, fremoteMove, true)
|
testServerSideMove(t, r, fremoteMove, true)
|
||||||
|
@ -24,11 +24,20 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Globals
|
||||||
var (
|
var (
|
||||||
// MatchTestRemote matches the remote names used for testing
|
RemoteName = flag.String("remote", "", "Remote to test with, defaults to local filesystem")
|
||||||
MatchTestRemote = regexp.MustCompile(`^rclone-test-[abcdefghijklmnopqrstuvwxyz0123456789]{24}$`)
|
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 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")
|
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
|
// 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
|
// Item represents an item for checking
|
||||||
type Item struct {
|
type Item struct {
|
||||||
Path string
|
Path string
|
||||||
|
@ -7,7 +7,6 @@ package fstests
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -48,12 +47,8 @@ var (
|
|||||||
Path: `hello? sausage/êé/Hello, 世界/ " ' @ < > & ? + ≠/z.txt`,
|
Path: `hello? sausage/êé/Hello, 世界/ " ' @ < > & ? + ≠/z.txt`,
|
||||||
WinPath: `hello_ sausage/êé/Hello, 世界/ _ ' @ _ _ & _ + ≠/z.txt`,
|
WinPath: `hello_ sausage/êé/Hello, 世界/ _ ' @ _ _ & _ + ≠/z.txt`,
|
||||||
}
|
}
|
||||||
file2Contents = ""
|
file2Contents = ""
|
||||||
verbose = flag.Bool("verbose", false, "Set to enable logging")
|
isLocalRemote bool
|
||||||
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
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExtraConfigItem describes a config item added on the fly while testing
|
// 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)
|
file2.Path = winPath(file2.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never ask for passwords, fail instead.
|
fstest.Initialise()
|
||||||
// If your local config is encrypted set environment variable
|
|
||||||
// "RCLONE_CONFIG_PASS=hunter2" (or your password)
|
|
||||||
*fs.AskPassword = false
|
|
||||||
fs.LoadConfig()
|
|
||||||
// Set extra config if supplied
|
// Set extra config if supplied
|
||||||
for _, item := range ExtraConfig {
|
for _, item := range ExtraConfig {
|
||||||
fs.ConfigFileSet(item.Name, item.Key, item.Value)
|
fs.ConfigFileSet(item.Name, item.Key, item.Value)
|
||||||
}
|
}
|
||||||
if *verbose {
|
if *fstest.RemoteName != "" {
|
||||||
fs.Config.LogLevel = fs.LogLevelDebug
|
RemoteName = *fstest.RemoteName
|
||||||
}
|
|
||||||
fs.Config.DumpHeaders = *dumpHeaders
|
|
||||||
fs.Config.DumpBodies = *dumpBodies
|
|
||||||
if *overrideRemote != "" {
|
|
||||||
RemoteName = *overrideRemote
|
|
||||||
}
|
}
|
||||||
t.Logf("Using remote %q", RemoteName)
|
t.Logf("Using remote %q", RemoteName)
|
||||||
if RemoteName == "" {
|
if RemoteName == "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user