diff --git a/fstest/test_all/clean.go b/fstest/test_all/clean.go index 6622f839b..3eb40ca4d 100644 --- a/fstest/test_all/clean.go +++ b/fstest/test_all/clean.go @@ -19,16 +19,24 @@ import ( var MatchTestRemote = regexp.MustCompile(`^rclone-test-[abcdefghijklmnopqrstuvwxyz0123456789]{24}(_segments)?$`) // cleanFs runs a single clean fs for left over directories -func cleanFs(remote string) error { +func cleanFs(ctx context.Context, remote string, cleanup bool) error { f, err := fs.NewFs(remote) if err != nil { return err } - entries, err := list.DirSorted(context.Background(), f, true, "") + var lastErr error + if cleanup { + log.Printf("%q - running cleanup", remote) + err = operations.CleanUp(ctx, f) + if err != nil { + lastErr = err + fs.Errorf(f, "Cleanup failed: %v", err) + } + } + entries, err := list.DirSorted(ctx, f, true, "") if err != nil { return err } - var lastErr error err = entries.ForDirError(func(dir fs.Directory) error { dirPath := dir.Remote() fullPath := remote + dirPath @@ -45,7 +53,7 @@ func cleanFs(remote string) error { fs.Errorf(fullPath, "%v", err) return nil } - err = operations.Purge(context.Background(), dir, "") + err = operations.Purge(ctx, dir, "") if err != nil { err = errors.Wrap(err, "Purge failed") lastErr = err @@ -62,11 +70,12 @@ func cleanFs(remote string) error { } // cleanRemotes cleans the list of remotes passed in -func cleanRemotes(remotes []string) error { +func cleanRemotes(conf *Config) error { var lastError error - for _, remote := range remotes { + for _, backend := range conf.Backends { + remote := backend.Remote log.Printf("%q - Cleaning", remote) - err := cleanFs(remote) + err := cleanFs(context.Background(), remote, backend.CleanUp) if err != nil { lastError = err log.Printf("Failed to purge %q: %v", remote, err) diff --git a/fstest/test_all/config.go b/fstest/test_all/config.go index 5724072c4..941c7caa5 100644 --- a/fstest/test_all/config.go +++ b/fstest/test_all/config.go @@ -33,6 +33,7 @@ type Backend struct { Short bool // set to test with -short OneOnly bool // set to run only one backend test at once MaxFile string // file size limit + CleanUp bool // when running clean, run cleanup first Ignore []string // test names to ignore the failure of Tests []string // paths of tests to run, blank for all } @@ -184,16 +185,3 @@ func (c *Config) filterTests(paths []string) { } c.Tests = newTests } - -// Remotes returns the unique remotes -func (c *Config) Remotes() (remotes []string) { - found := map[string]struct{}{} - for _, backend := range c.Backends { - if _, ok := found[backend.Remote]; ok { - continue - } - remotes = append(remotes, backend.Remote) - found[backend.Remote] = struct{}{} - } - return remotes -} diff --git a/fstest/test_all/config.yaml b/fstest/test_all/config.yaml index 4ebebe210..9a4671cd2 100644 --- a/fstest/test_all/config.yaml +++ b/fstest/test_all/config.yaml @@ -205,6 +205,7 @@ backends: remote: "TestQingStor:" fastlist: false oneonly: true + cleanup: true - backend: "azureblob" remote: "TestAzureBlob:" fastlist: true diff --git a/fstest/test_all/test_all.go b/fstest/test_all/test_all.go index cb2ee0e18..f464e1182 100644 --- a/fstest/test_all/test_all.go +++ b/fstest/test_all/test_all.go @@ -86,7 +86,7 @@ func main() { // Just clean the directories if required if *clean { - err := cleanRemotes(conf.Remotes()) + err := cleanRemotes(conf) if err != nil { log.Fatalf("Failed to clean: %v", err) }