Documentation ¶
Overview ¶
Package fstest provides fake implementations of the fs package.
These implementations can be used to mock out the file system in tests.
Index ¶
- type FailureFs
- type FakeFile
- func (f *FakeFile) Close() error
- func (f *FakeFile) Fd() uintptr
- func (f *FakeFile) Name() string
- func (f *FakeFile) Read(p []byte) (n int, err error)
- func (f *FakeFile) ReadAt(p []byte, off int64) (n int, err error)
- func (f *FakeFile) Seek(offset int64, whence int) (int64, error)
- func (f *FakeFile) Stat() (fi os.FileInfo, err error)
- func (f *FakeFile) Truncate(size int64) error
- func (f *FakeFile) Write(p []byte) (n int, err error)
- func (f *FakeFile) WriteString(s string) (ret int, err error)
- type FileNotFoundFs
- type RecordingFs
- func (r *RecordingFs) Create(name string) (fs.File, error)
- func (r *RecordingFs) HasAction(action string) bool
- func (r *RecordingFs) Mkdir(name string, perm os.FileMode) error
- func (r *RecordingFs) MkdirAll(path string, perm os.FileMode) error
- func (r *RecordingFs) Open(name string) (fs.File, error)
- func (r *RecordingFs) OpenFile(name string, flag int, perm os.FileMode) (fs.File, error)
- func (r *RecordingFs) Remove(name string) error
- func (r *RecordingFs) RemoveAll(path string) error
- func (r *RecordingFs) Rename(oldname, newname string) error
- func (r *RecordingFs) Stat(name string) (os.FileInfo, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FailureFs ¶
type FailureFs struct { RecordingFs Err error }
FailureFs is like RecordingFs, except the it returns an arbitrary error on operations.
type FakeFile ¶
type FakeFile struct {
// contains filtered or unexported fields
}
FakeFile represents a fake instance of the File interface.
Methods from FakeFile act like methods in os.File, but instead of working in a real file, they work in an internal string.
An instance of FakeFile is returned by RecordingFs.Open method.
type FileNotFoundFs ¶
type FileNotFoundFs struct {
RecordingFs
}
FileNotFoundFs is like RecordingFs, except that it returns ENOENT on Open, OpenFile and Remove.
func (*FileNotFoundFs) Remove ¶
func (r *FileNotFoundFs) Remove(name string) error
func (*FileNotFoundFs) RemoveAll ¶
func (r *FileNotFoundFs) RemoveAll(path string) error
type RecordingFs ¶
type RecordingFs struct { // FileContent is used to provide content for files opened using // RecordingFs. FileContent string // contains filtered or unexported fields }
RecordingFs implements the Fs interface providing a "recording" file system.
A recording file system is a file system that does not execute any action, just record them.
All methods from RecordingFs never return errors.
func (*RecordingFs) Create ¶
func (r *RecordingFs) Create(name string) (fs.File, error)
Create records the action "create <name>" and returns an instance of FakeFile and nil error.
func (*RecordingFs) HasAction ¶
func (r *RecordingFs) HasAction(action string) bool
HasAction checks if a given action was executed in the filesystem.
For example, when you call the Open method with the "/tmp/file.txt" argument, RecordingFs will store locally the action "open /tmp/file.txt" and you can check it calling HasAction:
rfs.Open("/tmp/file.txt") rfs.HasAction("open /tmp/file.txt") // true
func (*RecordingFs) Mkdir ¶
func (r *RecordingFs) Mkdir(name string, perm os.FileMode) error
Mkdir records the action "mkdir <name> with mode <perm>" and returns nil.
func (*RecordingFs) MkdirAll ¶
func (r *RecordingFs) MkdirAll(path string, perm os.FileMode) error
MkdirAll records the action "mkdirall <path> with mode <perm>" and returns nil.
func (*RecordingFs) Open ¶
func (r *RecordingFs) Open(name string) (fs.File, error)
Open records the action "open <name>" and returns an instance of FakeFile and nil error.
func (*RecordingFs) OpenFile ¶
OpenFile records the action "openfile <name> with mode <perm>" and returns an instance of FakeFile and nil error.
func (*RecordingFs) Remove ¶
func (r *RecordingFs) Remove(name string) error
Remove records the action "remove <name>" and returns nil.
func (*RecordingFs) RemoveAll ¶
func (r *RecordingFs) RemoveAll(path string) error
RemoveAll records the action "removeall <path>" and returns nil.
func (*RecordingFs) Rename ¶
func (r *RecordingFs) Rename(oldname, newname string) error