fstest: refactor to decouple package from implementation

This commit is contained in:
nielash
2025-08-24 03:07:59 -04:00
parent 7f5a444350
commit 6e9a675b3f
6 changed files with 138 additions and 113 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/rclone/rclone/fs/fspath"
"github.com/rclone/rclone/fs/list"
"github.com/rclone/rclone/fs/operations"
"github.com/rclone/rclone/fstest/runs"
)
// MatchTestRemote matches the remote names used for testing (copied
@@ -19,7 +20,7 @@ import (
var MatchTestRemote = regexp.MustCompile(`^rclone-test-[abcdefghijklmnopqrstuvwxyz0123456789]{12,24}(_segments)?$`)
// cleanFs runs a single clean fs for left over directories
func cleanFs(ctx context.Context, remote string, cleanup bool) error {
func cleanFs(ctx context.Context, remote string, cleanup bool, Opt runs.RunOpt) error {
f, err := fs.NewFs(context.Background(), remote)
if err != nil {
return err
@@ -41,7 +42,7 @@ func cleanFs(ctx context.Context, remote string, cleanup bool) error {
dirPath := dir.Remote()
fullPath := fspath.JoinRootPath(remote, dirPath)
if MatchTestRemote.MatchString(dirPath) {
if *dryRun {
if Opt.DryRun {
fs.Logf(nil, "Not Purging %s - -dry-run", fullPath)
return nil
}
@@ -70,12 +71,12 @@ func cleanFs(ctx context.Context, remote string, cleanup bool) error {
}
// cleanRemotes cleans the list of remotes passed in
func cleanRemotes(conf *Config) error {
func cleanRemotes(conf *runs.Config, Opt runs.RunOpt) error {
var lastError error
for _, backend := range conf.Backends {
remote := backend.Remote
fs.Logf(nil, "%q - Cleaning", remote)
err := cleanFs(context.Background(), remote, backend.CleanUp)
err := cleanFs(context.Background(), remote, backend.CleanUp, Opt)
if err != nil {
lastError = err
fs.Logf(nil, "Failed to purge %q: %v", remote, err)