2018-01-13 00:30:54 +08:00
|
|
|
// Run tests for all the remotes. Run this with package names which
|
|
|
|
// need integration testing.
|
2015-12-30 08:18:31 +08:00
|
|
|
//
|
2018-01-13 00:30:54 +08:00
|
|
|
// See the `test` target in the Makefile.
|
2015-12-30 08:18:31 +08:00
|
|
|
package main
|
|
|
|
|
2018-09-29 21:48:29 +08:00
|
|
|
/* FIXME
|
|
|
|
|
|
|
|
Make TesTrun have a []string of flags to try - that then makes it generic
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-12-30 08:18:31 +08:00
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
2018-10-24 17:33:38 +08:00
|
|
|
"math/rand"
|
2015-12-30 08:18:31 +08:00
|
|
|
"os"
|
2018-01-13 00:30:54 +08:00
|
|
|
"path"
|
2016-04-26 15:11:37 +08:00
|
|
|
"regexp"
|
2015-12-30 08:18:31 +08:00
|
|
|
"strings"
|
|
|
|
"time"
|
2016-01-04 05:49:26 +08:00
|
|
|
|
2019-07-29 01:47:38 +08:00
|
|
|
_ "github.com/rclone/rclone/backend/all" // import all fs
|
2021-03-30 06:12:53 +08:00
|
|
|
"github.com/rclone/rclone/fs/config/configfile"
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/lib/pacer"
|
2015-12-30 08:18:31 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Flags
|
2018-09-29 21:48:29 +08:00
|
|
|
maxTries = flag.Int("maxtries", 5, "Number of times to try each test")
|
2018-10-24 17:33:38 +08:00
|
|
|
maxN = flag.Int("n", 20, "Maximum number of tests to run at once")
|
2020-10-14 05:49:58 +08:00
|
|
|
testRemotes = flag.String("remotes", "", "Comma separated list of remotes to test, e.g. 'TestSwift:,TestS3'")
|
|
|
|
testBackends = flag.String("backends", "", "Comma separated list of backends to test, e.g. 's3,googlecloudstorage")
|
|
|
|
testTests = flag.String("tests", "", "Comma separated list of tests to test, e.g. 'fs/sync,fs/operations'")
|
2018-09-29 21:48:29 +08:00
|
|
|
clean = flag.Bool("clean", false, "Instead of testing, clean all left over test directories")
|
|
|
|
runOnly = flag.String("run", "", "Run only those tests matching the regexp supplied")
|
2020-05-08 03:38:40 +08:00
|
|
|
timeout = flag.Duration("timeout", 60*time.Minute, "Maximum time to run each test for before giving up")
|
2024-01-24 19:25:47 +08:00
|
|
|
race = flag.Bool("race", false, "If set run the tests under the race detector")
|
2018-09-29 21:48:29 +08:00
|
|
|
configFile = flag.String("config", "fstest/test_all/config.yaml", "Path to config file")
|
|
|
|
outputDir = flag.String("output", path.Join(os.TempDir(), "rclone-integration-tests"), "Place to store results")
|
|
|
|
emailReport = flag.String("email", "", "Set to email the report to the address supplied")
|
|
|
|
dryRun = flag.Bool("dry-run", false, "Print commands which would be executed only")
|
|
|
|
urlBase = flag.String("url-base", "https://pub.rclone.org/integration-tests/", "Base for the online version")
|
|
|
|
uploadPath = flag.String("upload", "", "Set this to an rclone path to upload the results here")
|
|
|
|
verbose = flag.Bool("verbose", false, "Set to enable verbose logging in the tests")
|
2020-05-08 03:36:45 +08:00
|
|
|
listRetries = flag.Int("list-retries", -1, "Number or times to retry listing - set to override the default")
|
2015-12-30 08:18:31 +08:00
|
|
|
)
|
|
|
|
|
2017-06-13 20:19:18 +08:00
|
|
|
// if matches then is definitely OK in the shell
|
|
|
|
var shellOK = regexp.MustCompile("^[A-Za-z0-9./_:-]+$")
|
|
|
|
|
2020-05-20 18:39:20 +08:00
|
|
|
// converts an argv style input into a shell command
|
2017-06-13 20:19:18 +08:00
|
|
|
func toShell(args []string) (result string) {
|
|
|
|
for _, arg := range args {
|
|
|
|
if result != "" {
|
|
|
|
result += " "
|
|
|
|
}
|
|
|
|
if shellOK.MatchString(arg) {
|
|
|
|
result += arg
|
|
|
|
} else {
|
|
|
|
result += "'" + arg + "'"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2018-09-29 21:48:29 +08:00
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
conf, err := NewConfig(*configFile)
|
2018-01-13 00:30:54 +08:00
|
|
|
if err != nil {
|
2018-09-29 21:48:29 +08:00
|
|
|
log.Println("test_all should be run from the root of the rclone source code")
|
|
|
|
log.Fatal(err)
|
2018-01-13 00:30:54 +08:00
|
|
|
}
|
2021-04-27 05:37:49 +08:00
|
|
|
configfile.Install()
|
2018-01-13 00:30:54 +08:00
|
|
|
|
2018-10-24 17:33:38 +08:00
|
|
|
// Seed the random number generator
|
2023-06-23 16:50:01 +08:00
|
|
|
randInstance := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
|
2018-10-24 17:33:38 +08:00
|
|
|
|
2018-09-29 21:48:29 +08:00
|
|
|
// Filter selection
|
|
|
|
if *testRemotes != "" {
|
|
|
|
conf.filterBackendsByRemotes(strings.Split(*testRemotes, ","))
|
2015-12-30 08:18:31 +08:00
|
|
|
}
|
2018-09-29 21:48:29 +08:00
|
|
|
if *testBackends != "" {
|
|
|
|
conf.filterBackendsByBackends(strings.Split(*testBackends, ","))
|
2015-12-30 08:18:31 +08:00
|
|
|
}
|
2018-09-29 21:48:29 +08:00
|
|
|
if *testTests != "" {
|
|
|
|
conf.filterTests(strings.Split(*testTests, ","))
|
2015-12-30 08:18:31 +08:00
|
|
|
}
|
|
|
|
|
2018-09-29 21:48:29 +08:00
|
|
|
// Just clean the directories if required
|
|
|
|
if *clean {
|
2020-03-31 22:56:58 +08:00
|
|
|
err := cleanRemotes(conf)
|
2018-09-29 21:48:29 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to clean: %v", err)
|
2017-06-07 06:04:01 +08:00
|
|
|
}
|
2018-09-29 21:48:29 +08:00
|
|
|
return
|
2015-12-30 08:18:31 +08:00
|
|
|
}
|
2018-09-29 21:48:29 +08:00
|
|
|
|
2017-06-07 06:04:01 +08:00
|
|
|
var names []string
|
2018-09-29 21:48:29 +08:00
|
|
|
for _, remote := range conf.Backends {
|
|
|
|
names = append(names, remote.Remote)
|
2017-06-07 06:04:01 +08:00
|
|
|
}
|
|
|
|
log.Printf("Testing remotes: %s", strings.Join(names, ", "))
|
2015-12-30 08:18:31 +08:00
|
|
|
|
2018-10-24 17:33:38 +08:00
|
|
|
// Runs we will do for this test in random order
|
2018-09-29 21:48:29 +08:00
|
|
|
runs := conf.MakeRuns()
|
2023-06-23 16:50:01 +08:00
|
|
|
randInstance.Shuffle(len(runs), runs.Swap)
|
2018-09-29 21:48:29 +08:00
|
|
|
|
|
|
|
// Create Report
|
|
|
|
report := NewReport()
|
|
|
|
|
|
|
|
// Make the test binaries, one per Path found in the tests
|
|
|
|
done := map[string]struct{}{}
|
|
|
|
for _, run := range runs {
|
|
|
|
if _, found := done[run.Path]; !found {
|
|
|
|
done[run.Path] = struct{}{}
|
2018-10-24 00:31:11 +08:00
|
|
|
if !run.NoBinary {
|
|
|
|
run.MakeTestBinary()
|
|
|
|
defer run.RemoveTestBinary()
|
|
|
|
}
|
2018-01-13 00:30:54 +08:00
|
|
|
}
|
2016-01-04 05:49:26 +08:00
|
|
|
}
|
2015-12-30 08:18:31 +08:00
|
|
|
|
2018-03-08 20:17:29 +08:00
|
|
|
// workaround for cache backend as we run simultaneous tests
|
|
|
|
_ = os.Setenv("RCLONE_CACHE_DB_WAIT_TIME", "30m")
|
|
|
|
|
2015-12-30 08:18:31 +08:00
|
|
|
// start the tests
|
2018-10-24 17:33:38 +08:00
|
|
|
results := make(chan *Run, len(runs))
|
2015-12-30 08:18:31 +08:00
|
|
|
awaiting := 0
|
2018-10-24 17:33:38 +08:00
|
|
|
tokens := pacer.NewTokenDispenser(*maxN)
|
2018-09-29 21:48:29 +08:00
|
|
|
for _, run := range runs {
|
2018-10-24 17:33:38 +08:00
|
|
|
tokens.Get()
|
|
|
|
go func(run *Run) {
|
|
|
|
defer tokens.Put()
|
|
|
|
run.Run(report.LogDir, results)
|
|
|
|
}(run)
|
2018-09-29 21:48:29 +08:00
|
|
|
awaiting++
|
2015-12-30 08:18:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for the tests to finish
|
|
|
|
for ; awaiting > 0; awaiting-- {
|
|
|
|
t := <-results
|
2018-09-29 21:48:29 +08:00
|
|
|
report.RecordResult(t)
|
2015-12-30 08:18:31 +08:00
|
|
|
}
|
|
|
|
|
2018-09-29 21:48:29 +08:00
|
|
|
// Log and exit
|
|
|
|
report.End()
|
|
|
|
report.LogSummary()
|
2019-09-08 18:35:56 +08:00
|
|
|
report.LogJSON()
|
2018-09-29 21:48:29 +08:00
|
|
|
report.LogHTML()
|
|
|
|
report.EmailHTML()
|
|
|
|
report.Upload()
|
|
|
|
if !report.AllPassed() {
|
2015-12-30 08:18:31 +08:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|