Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

fstest/mockobject: add SetFs method so it can have a valid Fs() #3419

Nick Craig-Woodec8e0a6c584a
diff --git a/fstest/mockobject/mockobject.go b/fstest/mockobject/mockobject.go
index 095508723..3f55e4d7c 100644
--- a/fstest/mockobject/mockobject.go
+++ b/fstest/mockobject/mockobject.go
@@ -93,22 +93,37 @@ const (
// SeekModes contains all valid SeekMode's
var SeekModes = []SeekMode{SeekModeNone, SeekModeRegular, SeekModeRange}
-type contentMockObject struct {
+// ContentMockObject mocks an fs.Object and has content
+type ContentMockObject struct {
Object
content []byte
seekMode SeekMode
+ f fs.Fs
}
// WithContent returns a fs.Object with the given content.
-func (o Object) WithContent(content []byte, mode SeekMode) fs.Object {
- return &contentMockObject{
+func (o Object) WithContent(content []byte, mode SeekMode) *ContentMockObject {
+ return &ContentMockObject{
Object: o,
content: content,
seekMode: mode,
}
}
-func (o *contentMockObject) Open(ctx context.Context, options ...fs.OpenOption) (io.ReadCloser, error) {
+// SetFs sets the return value of the Fs() call
+func (o *ContentMockObject) SetFs(f fs.Fs) {
+ o.f = f
+}
+
+// Fs returns read only access to the Fs that this object is part of
+//
+// This is nil unless SetFs has been called
+func (o *ContentMockObject) Fs() fs.Info {
+ return o.f
+}
+
+// Open opens the file for read. Call Close() on the returned io.ReadCloser
+func (o *ContentMockObject) Open(ctx context.Context, options ...fs.OpenOption) (io.ReadCloser, error) {
var offset, limit int64 = 0, -1
for _, option := range options {
switch x := option.(type) {
@@ -147,7 +162,9 @@ func (o *contentMockObject) Open(ctx context.Context, options ...fs.OpenOption)
return nil, errors.New(o.seekMode.String())
}
}
-func (o *contentMockObject) Size() int64 {
+
+// Size returns the size of the file
+func (o *ContentMockObject) Size() int64 {
return int64(len(o.content))
}