Documentation ¶
Index ¶
- Variables
- func WrapFile(f vfs.File, inj Injector) vfs.File
- type FS
- func (fs *FS) Create(name string) (vfs.File, error)
- func (fs *FS) GetDiskUsage(path string) (vfs.DiskUsage, error)
- func (fs *FS) Link(oldname, newname string) error
- func (fs *FS) List(dir string) ([]string, error)
- func (fs *FS) Lock(name string) (io.Closer, error)
- func (fs *FS) MkdirAll(dir string, perm os.FileMode) error
- func (fs *FS) Open(name string, opts ...vfs.OpenOption) (vfs.File, error)
- func (fs *FS) OpenDir(name string) (vfs.File, error)
- func (fs *FS) OpenReadWrite(name string, opts ...vfs.OpenOption) (vfs.File, error)
- func (fs *FS) PathBase(p string) string
- func (fs *FS) PathDir(p string) string
- func (fs *FS) PathJoin(elem ...string) string
- func (fs *FS) Remove(name string) error
- func (fs *FS) RemoveAll(fullname string) error
- func (fs *FS) Rename(oldname, newname string) error
- func (fs *FS) ReuseForWrite(oldname, newname string) (vfs.File, error)
- func (fs *FS) Stat(name string) (os.FileInfo, error)
- func (fs *FS) Unwrap() vfs.FS
- type InjectIndex
- type Injector
- type InjectorFunc
- type Op
- type OpKind
Constants ¶
This section is empty.
Variables ¶
var ErrInjected = errors.New("injected error")
ErrInjected is an error artificially injected for testing fs error paths.
Functions ¶
Types ¶
type FS ¶
type FS struct {
// contains filtered or unexported fields
}
FS implements vfs.FS, injecting errors into its operations.
func Wrap ¶
Wrap wraps an existing vfs.FS implementation, returning a new vfs.FS implementation that shadows operations to the provided FS. It uses the provided Injector for deciding when to inject errors. If an error is injected, FS propagates the error instead of shadowing the operation.
func (*FS) GetDiskUsage ¶
GetDiskUsage implements FS.GetDiskUsage.
func (*FS) OpenReadWrite ¶
OpenReadWrite implements FS.OpenReadWrite.
func (*FS) ReuseForWrite ¶
ReuseForWrite implements FS.ReuseForWrite.
type InjectIndex ¶
type InjectIndex struct {
// contains filtered or unexported fields
}
InjectIndex implements Injector, injecting an error at a specific index.
func OnIndex ¶
func OnIndex(index int32) *InjectIndex
OnIndex constructs an injector that returns an error on the (n+1)-th invocation of its MaybeError function. It may be passed to Wrap to inject an error into an FS.
func (*InjectIndex) Index ¶
func (ii *InjectIndex) Index() int32
Index returns the index at which the error will be injected.
func (*InjectIndex) MaybeError ¶
func (ii *InjectIndex) MaybeError(_ Op, _ string) error
MaybeError implements the Injector interface.
func (*InjectIndex) SetIndex ¶
func (ii *InjectIndex) SetIndex(v int32)
SetIndex sets the index at which the error will be injected.
type Injector ¶
type Injector interface { // MaybeError is invoked by an errorfs before an operation is executed. It // is passed an enum indicating the type of operation and a path of the // subject file or directory. If the operation takes two paths (eg, // Rename, Link), the original source path is provided. MaybeError(op Op, path string) error }
Injector injects errors into FS operations.
func WithProbability ¶
WithProbability returns a function that returns an error with the provided probability when passed op. It may be passed to Wrap to inject an error into an ErrFS with the provided probability. p should be within the range [0.0,1.0].
type InjectorFunc ¶
InjectorFunc implements the Injector interface for a function with MaybeError's signature.
func (InjectorFunc) MaybeError ¶
func (f InjectorFunc) MaybeError(op Op, path string) error
MaybeError implements the Injector interface.
type Op ¶
type Op int
Op is an enum describing the type of operation.
const ( // OpCreate describes a create file operation. OpCreate Op = iota // OpLink describes a hardlink operation. OpLink // OpOpen describes a file open operation. OpOpen // OpOpenDir describes a directory open operation. OpOpenDir // OpRemove describes a remove file operation. OpRemove // OpRemoveAll describes a recursive remove operation. OpRemoveAll // OpRename describes a rename operation. OpRename // OpReuseForRewrite describes a reuse for rewriting operation. OpReuseForRewrite // OpMkdirAll describes a make directory including parents operation. OpMkdirAll // OpLock describes a lock file operation. OpLock // OpList describes a list directory operation. OpList // OpFilePreallocate describes a file preallocate operation. OpFilePreallocate // OpStat describes a path-based stat operation. OpStat // OpGetDiskUsage describes a disk usage operation. OpGetDiskUsage // OpFileClose describes a close file operation. OpFileClose // OpFileRead describes a file read operation. OpFileRead // OpFileReadAt describes a file seek read operation. OpFileReadAt // OpFileWrite describes a file write operation. OpFileWrite // OpFileWriteAt describes a file seek write operation. OpFileWriteAt // OpFileStat describes a file stat operation. OpFileStat // OpFileSync describes a file sync operation. OpFileSync // OpFileFlush describes a file flush operation. OpFileFlush )