Documentation ¶
Overview ¶
Package mockfs implements in-memory filesystem for testing.
Index ¶
- Variables
- type Directory
- func (imd *Directory) AddDir(name string, permissions os.FileMode) *Directory
- func (imd *Directory) AddDirDevice(name string, permissions os.FileMode, deviceInfo fs.DeviceInfo) *Directory
- func (imd *Directory) AddErrorEntry(name string, permissions os.FileMode, err error) *ErrorEntry
- func (imd *Directory) AddFile(name string, content []byte, permissions os.FileMode) *File
- func (imd *Directory) AddFileDevice(name string, content []byte, permissions os.FileMode, deviceInfo fs.DeviceInfo) *File
- func (imd *Directory) AddFileLines(name string, lines []string, permissions os.FileMode) *File
- func (imd *Directory) AddFileWithSource(name string, permissions os.FileMode, ...) *File
- func (imd *Directory) AddSymlink(name, target string, permissions os.FileMode) *Symlink
- func (imd *Directory) Child(ctx context.Context, name string) (fs.Entry, error)
- func (e *Directory) Close()
- func (e *Directory) Device() fs.DeviceInfo
- func (imd *Directory) FailReaddir(err error)
- func (e *Directory) IsDir() bool
- func (imd *Directory) IterateEntries(ctx context.Context, cb func(context.Context, fs.Entry) error) error
- func (e *Directory) LocalFilesystemPath() string
- func (e *Directory) ModTime() time.Time
- func (e *Directory) Mode() os.FileMode
- func (e *Directory) Name() string
- func (imd *Directory) OnReaddir(cb func())
- func (e *Directory) Owner() fs.OwnerInfo
- func (imd *Directory) Remove(name string)
- func (e *Directory) Size() int64
- func (imd *Directory) Subdir(name ...string) *Directory
- func (imd *Directory) SupportsMultipleIterations() bool
- func (e *Directory) Sys() interface{}
- type ErrorEntry
- func (e *ErrorEntry) Close()
- func (e *ErrorEntry) Device() fs.DeviceInfo
- func (e *ErrorEntry) ErrorInfo() error
- func (e *ErrorEntry) IsDir() bool
- func (e *ErrorEntry) LocalFilesystemPath() string
- func (e *ErrorEntry) ModTime() time.Time
- func (e *ErrorEntry) Mode() os.FileMode
- func (e *ErrorEntry) Name() string
- func (e *ErrorEntry) Owner() fs.OwnerInfo
- func (e *ErrorEntry) Size() int64
- func (e *ErrorEntry) Sys() interface{}
- type File
- func (e *File) Close()
- func (e *File) Device() fs.DeviceInfo
- func (e *File) IsDir() bool
- func (e *File) LocalFilesystemPath() string
- func (e *File) ModTime() time.Time
- func (e *File) Mode() os.FileMode
- func (e *File) Name() string
- func (imf *File) Open(ctx context.Context) (fs.Reader, error)
- func (e *File) Owner() fs.OwnerInfo
- func (imf *File) SetContents(b []byte)
- func (e *File) Size() int64
- func (e *File) Sys() interface{}
- type ReaderSeekerCloser
- type Symlink
- func (e *Symlink) Close()
- func (e *Symlink) Device() fs.DeviceInfo
- func (e *Symlink) IsDir() bool
- func (e *Symlink) LocalFilesystemPath() string
- func (e *Symlink) ModTime() time.Time
- func (e *Symlink) Mode() os.FileMode
- func (e *Symlink) Name() string
- func (e *Symlink) Owner() fs.OwnerInfo
- func (imsl *Symlink) Readlink(ctx context.Context) (string, error)
- func (e *Symlink) Size() int64
- func (e *Symlink) Sys() interface{}
Constants ¶
This section is empty.
Variables ¶
var DefaultModTime = time.Date(2021, 1, 2, 3, 4, 5, 0, time.UTC)
DefaultModTime is the default modification time for mock filesystem entries.
Functions ¶
This section is empty.
Types ¶
type Directory ¶
type Directory struct {
// contains filtered or unexported fields
}
Directory is mock in-memory implementation of fs.Directory.
func (*Directory) AddDirDevice ¶ added in v0.8.0
func (imd *Directory) AddDirDevice(name string, permissions os.FileMode, deviceInfo fs.DeviceInfo) *Directory
AddDirDevice adds a fake directory with a given name and permissions.
func (*Directory) AddErrorEntry ¶ added in v0.8.0
AddErrorEntry adds a fake directory with a given name and permissions.
func (*Directory) AddFile ¶
AddFile adds a mock file with the specified name, content and permissions.
func (*Directory) AddFileDevice ¶ added in v0.8.0
func (imd *Directory) AddFileDevice(name string, content []byte, permissions os.FileMode, deviceInfo fs.DeviceInfo) *File
AddFileDevice adds a mock file with the specified name, content, permissions, and device info.
func (*Directory) AddFileLines ¶
AddFileLines adds a mock file with the specified name, text content and permissions.
func (*Directory) AddFileWithSource ¶ added in v0.12.0
func (imd *Directory) AddFileWithSource(name string, permissions os.FileMode, source func() (ReaderSeekerCloser, error)) *File
AddFileWithSource adds a mock file with the specified name, permissions, and given source function for getting a Reader instance.
func (*Directory) AddSymlink ¶ added in v0.9.5
AddSymlink adds a mock symlink with the specified name, target and permissions.
func (*Directory) Device ¶ added in v0.8.0
func (e *Directory) Device() fs.DeviceInfo
func (*Directory) FailReaddir ¶
FailReaddir causes the subsequent IterateEntries() calls to fail with the specified error.
func (*Directory) IterateEntries ¶ added in v0.11.0
func (imd *Directory) IterateEntries(ctx context.Context, cb func(context.Context, fs.Entry) error) error
IterateEntries calls the given callback on each entry in the directory.
func (*Directory) LocalFilesystemPath ¶ added in v0.8.0
func (e *Directory) LocalFilesystemPath() string
func (*Directory) OnReaddir ¶ added in v0.6.0
func (imd *Directory) OnReaddir(cb func())
OnReaddir invokes the provided function on read.
func (*Directory) SupportsMultipleIterations ¶ added in v0.11.0
SupportsMultipleIterations returns whether this directory can be iterated through multiple times.
type ErrorEntry ¶ added in v0.8.0
type ErrorEntry struct {
// contains filtered or unexported fields
}
ErrorEntry is mock in-memory implementation of fs.ErrorEntry.
func (*ErrorEntry) Device ¶ added in v0.8.0
func (e *ErrorEntry) Device() fs.DeviceInfo
func (*ErrorEntry) ErrorInfo ¶ added in v0.8.0
func (e *ErrorEntry) ErrorInfo() error
ErrorInfo implements fs.ErrorErntry.
func (*ErrorEntry) LocalFilesystemPath ¶ added in v0.8.0
func (e *ErrorEntry) LocalFilesystemPath() string
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is an in-memory fs.File capable of simulating failures.
func NewFile ¶ added in v0.11.0
NewFile returns a new mock file with the given name, contents, and mode.
func (*File) Device ¶ added in v0.8.0
func (e *File) Device() fs.DeviceInfo
func (*File) LocalFilesystemPath ¶ added in v0.8.0
func (e *File) LocalFilesystemPath() string
func (*File) SetContents ¶
SetContents changes the contents of a given file.
type ReaderSeekerCloser ¶
ReaderSeekerCloser implements io.Reader, io.Seeker and io.Closer.
type Symlink ¶ added in v0.9.5
type Symlink struct {
// contains filtered or unexported fields
}
Symlink is a mock implementation of the fs.Symlink interface.
func (*Symlink) Device ¶ added in v0.9.5
func (e *Symlink) Device() fs.DeviceInfo
func (*Symlink) LocalFilesystemPath ¶ added in v0.9.5
func (e *Symlink) LocalFilesystemPath() string