Documentation ¶
Overview ¶
Package lfilemock provides some mock file objects. This is not meant to be exhaustive, it is used to cover the cases needed to test luce. Over time it will expand.
Index ¶
- Constants
- type ByteFile
- type DirEntry
- type Directory
- func (d *Directory) AddDir(name string) *Directory
- func (d *Directory) AddFile(name string, contents []byte) *ByteFile
- func (d *Directory) DirEntry() os.DirEntry
- func (d *Directory) File() *File
- func (d *Directory) Get(path string) (n Node, found bool)
- func (d *Directory) Next(key string, create bool, _ navigator.VoidContext) (Node, bool)
- func (d *Directory) Repository() lfile.Repository
- type File
- type FileInfo
- type Node
- type Repository
Constants ¶
const ( ErrNewType = lerr.Str("lfilemock.New contents must be string or []byte") ErrParseType = lerr.Str("lfilemock.Parse values must be string, []byte or map[string]any") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByteFile ¶
ByteFile is used to create files in mock directory trees. ByteFiles are created when calling ParseDir.
func (*ByteFile) DirEntry ¶
DirEntry fulfills Node. It creates a DirEntry instance for the ByteFile.
type DirEntry ¶
DirEntry fulfills os.DirEntry.
type Directory ¶
Directory is used to create mock directory trees. Directories are created when calling ParseDir.
func Parse ¶
ParseDir allows for mock directory trees to be setup easily. To create a File the value can be either a string or a []byte. To create a sub directory the value should be another map[string]any which will be recursivly parsed.
func (*Directory) AddDir ¶
AddDir adds a sub directory. This can be used when modifying the mock directory tree.
func (*Directory) AddFile ¶
AddFile adds a ByteFile. This can be used when modifying the mock directory tree.
func (*Directory) DirEntry ¶
DirEntry fulfills Node. It creates a DirEntry instance for the Directory.
func (*Directory) File ¶
File fulfills Node. It creates an instance of *File that fulfills lfile.File.
func (*Directory) Next ¶
Next fulfills Node and navigator.Nexter. It is used internally for navigating the mock directory.
func (*Directory) Repository ¶
func (d *Directory) Repository() lfile.Repository
Parse allows for mock directory trees to be setup easily. To create a File the value can be either a string or a []byte. To create a sub directory the value should be another map[string]any which will be recursivly parsed. The returned Repository fulfills lfile.Repository.
type File ¶
type File struct { FileName string *bytes.Buffer Dir bool DirEntries []os.DirEntry os.FileInfo FileSize int64 os.FileMode Err error }
File mock allows for *os.File to be simulated including various errors.
type Node ¶
type Node interface { File() *File DirEntry() os.DirEntry Next(key string, create bool, vc navigator.VoidContext) (Node, bool) }
Node is fulfilled by ByteFile and Directory creating a mock directory tree.
type Repository ¶
type Repository struct {
Node
}
Repository fulfills lfile.Repository and is intended to mock a File system.
func (*Repository) Create ¶
func (r *Repository) Create(name string) (lfile.File, error)
Create fulfills lfile.Repository. It creates a file.
func (*Repository) Open ¶
func (r *Repository) Open(name string) (lfile.File, error)
Open fulfills lfile.Repository. It opens a file or directory if it exists.
func (*Repository) Remove ¶
func (r *Repository) Remove(name string) error
Remove fulfills lfile.Repository. It removes a file if it exists.