github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/fstest/mockfs/mockfs.go (about)

     1  package mockfs
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"fmt"
     7  	"io"
     8  	"time"
     9  
    10  	"github.com/ncw/rclone/fs"
    11  	"github.com/ncw/rclone/fs/hash"
    12  )
    13  
    14  // Fs is a minimal mock Fs
    15  type Fs struct {
    16  	name     string       // the name of the remote
    17  	root     string       // The root directory (OS path)
    18  	features *fs.Features // optional features
    19  }
    20  
    21  // ErrNotImplemented is returned by unimplemented methods
    22  var ErrNotImplemented = errors.New("not implemented")
    23  
    24  // NewFs returns a new mock Fs
    25  func NewFs(name, root string) *Fs {
    26  	f := &Fs{
    27  		name: name,
    28  		root: root,
    29  	}
    30  	f.features = (&fs.Features{}).Fill(f)
    31  	return f
    32  }
    33  
    34  // Name of the remote (as passed into NewFs)
    35  func (f *Fs) Name() string {
    36  	return f.name
    37  }
    38  
    39  // Root of the remote (as passed into NewFs)
    40  func (f *Fs) Root() string {
    41  	return f.root
    42  }
    43  
    44  // String returns a description of the FS
    45  func (f *Fs) String() string {
    46  	return fmt.Sprintf("Mock file system at %s", f.root)
    47  }
    48  
    49  // Precision of the ModTimes in this Fs
    50  func (f *Fs) Precision() time.Duration {
    51  	return time.Second
    52  }
    53  
    54  // Hashes returns the supported hash types of the filesystem
    55  func (f *Fs) Hashes() hash.Set {
    56  	return hash.NewHashSet()
    57  }
    58  
    59  // Features returns the optional features of this Fs
    60  func (f *Fs) Features() *fs.Features {
    61  	return f.features
    62  }
    63  
    64  // List the objects and directories in dir into entries.  The
    65  // entries can be returned in any order but should be for a
    66  // complete directory.
    67  //
    68  // dir should be "" to list the root, and should not have
    69  // trailing slashes.
    70  //
    71  // This should return ErrDirNotFound if the directory isn't
    72  // found.
    73  func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err error) {
    74  	return nil, nil
    75  }
    76  
    77  // NewObject finds the Object at remote.  If it can't be found
    78  // it returns the error ErrorObjectNotFound.
    79  func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) {
    80  	return nil, fs.ErrorObjectNotFound
    81  }
    82  
    83  // Put in to the remote path with the modTime given of the given size
    84  //
    85  // May create the object even if it returns an error - if so
    86  // will return the object and the error, otherwise will return
    87  // nil and the error
    88  func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error) {
    89  	return nil, ErrNotImplemented
    90  }
    91  
    92  // Mkdir makes the directory (container, bucket)
    93  //
    94  // Shouldn't return an error if it already exists
    95  func (f *Fs) Mkdir(ctx context.Context, dir string) error {
    96  	return ErrNotImplemented
    97  }
    98  
    99  // Rmdir removes the directory (container, bucket) if empty
   100  //
   101  // Return an error if it doesn't exist or isn't empty
   102  func (f *Fs) Rmdir(ctx context.Context, dir string) error {
   103  	return ErrNotImplemented
   104  }
   105  
   106  // Assert it is the correct type
   107  var _ fs.Fs = (*Fs)(nil)