Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrFileOperationNotPermitted = errors.New("fake file does not exist and therefore this operation is not permitted.") ErrFileDoesNotExist = errors.New("fake file does not exist") )
var DefaultFilesystem = OSFileSystem{}
DefaultFilesystem is the default implementation of the FileSystem interface. It uses OSFileSystem to make functions of the os package the default for users.
Functions ¶
This section is empty.
Types ¶
type FakeFile ¶
Fake represents are readable in memory version of os.File which can be used for testing.
func NewFakeFile ¶
NewFakeFile creates a new FakeFile instances based on a file name and it's contents from strings. The content of the new instance will be stored in an internal bytes.Reader instance. The default file mode will be 0777 and the last modification time the moment when the function is called.
func (FakeFile) Read ¶
Read wraps io.Reader's functionality around the internal bytes.Reader instance.
func (FakeFile) ReadAt ¶
ReadAt wraps io.ReaderAt's functionality around the internalt bytes.Reader instance.
type FakeFileInfo ¶
type FakeFileInfo struct {
File FakeFile
}
FakeFileInfo describes a wrapped FakeFile instance and is returned by FakeFile.Stat
func (FakeFileInfo) IsDir ¶
func (fi FakeFileInfo) IsDir() bool
IsDir always return false since it only uses FakeFile instances.
func (FakeFileInfo) ModTime ¶
func (fi FakeFileInfo) ModTime() time.Time
ModTime returns the modification time of the FakeFile instance.
func (FakeFileInfo) Mode ¶
func (fi FakeFileInfo) Mode() os.FileMode
Mode returns file mode bits of the FakeFile instance.
func (FakeFileInfo) Name ¶
func (fi FakeFileInfo) Name() string
Name returns the base name of the FakeFile instance.
func (FakeFileInfo) Size ¶
func (fi FakeFileInfo) Size() int64
Size returns the length in bytes of the file's internal bytes.Reader instance.
func (FakeFileInfo) Sys ¶
func (fi FakeFileInfo) Sys() interface{}
Sys always returns nil to stay conformant to the os.FileInfo interface.
type FakeFilesystem ¶
type FakeFilesystem struct {
// contains filtered or unexported fields
}
FakeFilesystem in memory implementations for the functions of the FileSystem interface to offer an implementation that can be used during in tests.
func NewFakeFilesystemWithFiles ¶
func NewFakeFilesystemWithFiles(fs []FakeFile) FakeFilesystem
NewFakeFilesystemWithFiles creates a new FakeFilesystem instance bundled with a list of FakeFile instances that can be passed.
func (FakeFilesystem) Open ¶
func (ff FakeFilesystem) Open(name string) (File, error)
Open searches in the internal map of FakeFile instances and returns it for reading. If successful, methods on the returned file can be used for reading. If the FakeFile instance cannot be found in the internal map an error of type *PathError will be returned.
func (FakeFilesystem) Stat ¶
func (ff FakeFilesystem) Stat(name string) (os.FileInfo, error)
Stat returns the FakeFileInfo structure describing a FakeFile instance Found in the internal FakeFile map. If the FakeFile instance cannot be found in the internal map an error of type *PathError will be returned.
type File ¶
File is an interface that groups several read interfaces of the io package together with the Stat function of the os package to make reading astractions of the filesystem possible.
type FileSystem ¶
type FileSystem interface {
Open(name string) (File, error)
Stat(name string) (os.FileInfo, error)
}
FileSystem is an interface that groups the common functions Open and Stat of the os package.
type OSFileSystem ¶
type OSFileSystem struct{}
OSFileSystem wraps the functions of the FileSystem interface around functions of the os package to offer an abstraction for the golang library.