"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
fstest/mockfs: allow fs.Objects to be added to the root
Nick Craig-Woodea9b6087cf70
diff --git a/fstest/mockfs/mockfs.go b/fstest/mockfs/mockfs.goindex 476864e73..ed2d1b5e6 100644--- a/fstest/mockfs/mockfs.go+++ b/fstest/mockfs/mockfs.go@@ -5,6 +5,7 @@ import ("errors""fmt""io"+ "path""time""github.com/rclone/rclone/fs"@@ -13,9 +14,10 @@ import (// Fs is a minimal mock Fstype Fs struct {- name string // the name of the remote- root string // The root directory (OS path)- features *fs.Features // optional features+ name string // the name of the remote+ root string // The root directory (OS path)+ features *fs.Features // optional features+ rootDir fs.DirEntries // directory listing of root}// ErrNotImplemented is returned by unimplemented methods@@ -31,6 +33,17 @@ func NewFs(name, root string) *Fs {return f}+// AddObject adds an Object for List to return+// Only works for the root for the moment+func (f *Fs) AddObject(o fs.Object) {+ f.rootDir = append(f.rootDir, o)+ // Make this object part of mockfs if possible+ do, ok := o.(interface{ SetFs(f fs.Fs) })+ if ok {+ do.SetFs(f)+ }+}+// Name of the remote (as passed into NewFs)func (f *Fs) Name() string {return f.name@@ -71,12 +84,23 @@ func (f *Fs) Features() *fs.Features {// This should return ErrDirNotFound if the directory isn't// found.func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err error) {- return nil, nil+ if dir == "" {+ return f.rootDir, nil+ }+ return entries, fs.ErrorDirNotFound}// NewObject finds the Object at remote. If it can't be found// it returns the error ErrorObjectNotFound.func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) {+ dirPath := path.Dir(remote)+ if dirPath == "" || dirPath == "." {+ for _, entry := range f.rootDir {+ if entry.Remote() == remote {+ return entry.(fs.Object), nil+ }+ }+ }return nil, fs.ErrorObjectNotFound}