"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/mockobject: add UnknownSize() method to make Size() return -1
Nick Craig-Wood2e80e035c9b1
diff --git a/fstest/mockobject/mockobject.go b/fstest/mockobject/mockobject.goindex 3f55e4d7c..a444d0617 100644--- a/fstest/mockobject/mockobject.go+++ b/fstest/mockobject/mockobject.go@@ -96,9 +96,10 @@ var SeekModes = []SeekMode{SeekModeNone, SeekModeRegular, SeekModeRange}// ContentMockObject mocks an fs.Object and has contenttype ContentMockObject struct {Object- content []byte- seekMode SeekMode- f fs.Fs+ content []byte+ seekMode SeekMode+ f fs.Fs+ unknownSize bool}// WithContent returns a fs.Object with the given content.@@ -115,6 +116,11 @@ func (o *ContentMockObject) SetFs(f fs.Fs) {o.f = f}+// SetUnknownSize makes the mock object return -1 for size if true+func (o *ContentMockObject) SetUnknownSize(unknownSize bool) {+ o.unknownSize = true+}+// Fs returns read only access to the Fs that this object is part of//// This is nil unless SetFs has been called@@ -124,21 +130,22 @@ func (o *ContentMockObject) Fs() fs.Info {// Open opens the file for read. Call Close() on the returned io.ReadCloserfunc (o *ContentMockObject) Open(ctx context.Context, options ...fs.OpenOption) (io.ReadCloser, error) {+ size := int64(len(o.content))var offset, limit int64 = 0, -1for _, option := range options {switch x := option.(type) {case *fs.SeekOption:offset = x.Offsetcase *fs.RangeOption:- offset, limit = x.Decode(o.Size())+ offset, limit = x.Decode(size)default:if option.Mandatory() {return nil, fmt.Errorf("Unsupported mandatory option: %v", option)}}}- if limit == -1 || offset+limit > o.Size() {- limit = o.Size() - offset+ if limit == -1 || offset+limit > size {+ limit = size - offset}var r *bytes.Reader@@ -165,6 +172,9 @@ func (o *ContentMockObject) Open(ctx context.Context, options ...fs.OpenOption)// Size returns the size of the filefunc (o *ContentMockObject) Size() int64 {+ if o.unknownSize {+ return -1+ }return int64(len(o.content))}