Documentation
¶
Overview ¶
--- START OF FILE internal/filesystem/mock_filesystem.go ---
Index ¶
- type FileSystem
- type MockFileSystem
- func (mfs *MockFileSystem) AddDir(path string, modTime time.Time)
- func (mfs *MockFileSystem) AddFile(path string, content []byte, modTime time.Time)
- func (mfs *MockFileSystem) AssertRemoveCalled(t *testing.T, path string)
- func (mfs *MockFileSystem) AssertRemoveNotCalled(t *testing.T, path string)
- func (mfs *MockFileSystem) AssertRenameCalled(t *testing.T, oldpath string)
- func (mfs *MockFileSystem) AssertWriteCalled(t *testing.T, path string)
- func (mfs *MockFileSystem) AssertWriteNotCalled(t *testing.T, path string)
- func (mfs *MockFileSystem) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (mfs *MockFileSystem) MkdirAll(path string, perm fs.FileMode) error
- func (mfs *MockFileSystem) ReadFile(name string) ([]byte, error)
- func (mfs *MockFileSystem) Remove(name string) error
- func (mfs *MockFileSystem) Rename(oldpath, newpath string) error
- func (mfs *MockFileSystem) SetWalkError(err error)
- func (mfs *MockFileSystem) SimulateMkdirError(path string, err error)
- func (mfs *MockFileSystem) SimulateReadError(path string, err error)
- func (mfs *MockFileSystem) SimulateRemoveError(path string, err error)
- func (mfs *MockFileSystem) SimulateRenameError(path string, err error)
- func (mfs *MockFileSystem) SimulateStatError(path string, err error)
- func (mfs *MockFileSystem) SimulateWriteError(path string, err error)
- func (mfs *MockFileSystem) Stat(name string) (fs.FileInfo, error)
- func (mfs *MockFileSystem) WalkDir(root string, fn fs.WalkDirFunc) error
- func (mfs *MockFileSystem) WriteFile(name string, data []byte, perm fs.FileMode) error
- type RealFileSystem
- func (rfs *RealFileSystem) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (rfs *RealFileSystem) MkdirAll(path string, perm fs.FileMode) error
- func (rfs *RealFileSystem) ReadFile(name string) ([]byte, error)
- func (rfs *RealFileSystem) Remove(name string) error
- func (rfs *RealFileSystem) Rename(oldpath, newpath string) error
- func (rfs *RealFileSystem) Stat(name string) (fs.FileInfo, error)
- func (rfs *RealFileSystem) WalkDir(root string, fn fs.WalkDirFunc) error
- func (rfs *RealFileSystem) WriteFile(name string, data []byte, perm fs.FileMode) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileSystem ¶
type FileSystem interface {
// ReadFile reads the named file and returns the contents.
ReadFile(name string) ([]byte, error)
// WriteFile writes data to the named file, creating it if necessary.
// If the file does not exist, WriteFile creates it with permissions perm;
// otherwise WriteFile truncates it before writing, without changing permissions.
WriteFile(name string, data []byte, perm fs.FileMode) error
// Stat returns a FileInfo describing the named file.
Stat(name string) (fs.FileInfo, error)
// MkdirAll creates a directory named path,
// along with any necessary parents, and returns nil,
// or else returns an error.
// The permission bits perm (before umask) are used for all
// directories that MkdirAll creates.
MkdirAll(path string, perm fs.FileMode) error
// WalkDir walks the file tree rooted at root, calling fn for each file or
// directory in the tree, including root.
// All errors that arise visiting files or directories are filtered by fn:
// see the WalkDirFunc documentation for details.
WalkDir(root string, fn fs.WalkDirFunc) error
// Remove removes the named file or (empty) directory.
Remove(name string) error
// Rename renames (moves) oldpath to newpath.
// If newpath already exists and is not a directory, Rename replaces it.
// OS-specific restrictions may apply when oldpath and newpath are in different directories.
Rename(oldpath, newpath string) error
// Chtimes changes the modification time of the named file.
// Added potentially for cache testing scenarios or specific filesystem interactions.
Chtimes(name string, atime time.Time, mtime time.Time) error
}
FileSystem defines an interface for interacting with the filesystem. This allows for decoupling core logic from the OS package, facilitating testing. Conforms to specifications required by TASK-CONVI-020.
type MockFileSystem ¶
MockFileSystem implements the FileSystem interface for testing purposes. It uses testify/mock to allow setting expectations and asserting calls.
func NewMockFileSystem ¶
func NewMockFileSystem() *MockFileSystem
NewMockFileSystem creates a new instance of MockFileSystem, ready for use.
func (*MockFileSystem) AddDir ¶
func (mfs *MockFileSystem) AddDir(path string, modTime time.Time)
AddDir adds a directory entry to the mock filesystem.
func (*MockFileSystem) AddFile ¶
func (mfs *MockFileSystem) AddFile(path string, content []byte, modTime time.Time)
AddFile adds a file with content and modification time to the mock filesystem.
func (*MockFileSystem) AssertRemoveCalled ¶
func (mfs *MockFileSystem) AssertRemoveCalled(t *testing.T, path string)
func (*MockFileSystem) AssertRemoveNotCalled ¶
func (mfs *MockFileSystem) AssertRemoveNotCalled(t *testing.T, path string)
func (*MockFileSystem) AssertRenameCalled ¶
func (mfs *MockFileSystem) AssertRenameCalled(t *testing.T, oldpath string)
func (*MockFileSystem) AssertWriteCalled ¶
func (mfs *MockFileSystem) AssertWriteCalled(t *testing.T, path string)
func (*MockFileSystem) AssertWriteNotCalled ¶
func (mfs *MockFileSystem) AssertWriteNotCalled(t *testing.T, path string)
func (*MockFileSystem) MkdirAll ¶
func (mfs *MockFileSystem) MkdirAll(path string, perm fs.FileMode) error
MkdirAll simulates creating directories in the mock filesystem.
func (*MockFileSystem) ReadFile ¶
func (mfs *MockFileSystem) ReadFile(name string) ([]byte, error)
ReadFile simulates reading a file from the mock filesystem.
func (*MockFileSystem) Remove ¶
func (mfs *MockFileSystem) Remove(name string) error
Remove simulates removing a file or directory from the mock filesystem.
func (*MockFileSystem) Rename ¶
func (mfs *MockFileSystem) Rename(oldpath, newpath string) error
Rename simulates renaming (moving) a file or directory.
func (*MockFileSystem) SetWalkError ¶
func (mfs *MockFileSystem) SetWalkError(err error)
SetWalkError sets a global error to be returned by the WalkDir simulation.
func (*MockFileSystem) SimulateMkdirError ¶
func (mfs *MockFileSystem) SimulateMkdirError(path string, err error)
func (*MockFileSystem) SimulateReadError ¶
func (mfs *MockFileSystem) SimulateReadError(path string, err error)
func (*MockFileSystem) SimulateRemoveError ¶
func (mfs *MockFileSystem) SimulateRemoveError(path string, err error)
func (*MockFileSystem) SimulateRenameError ¶
func (mfs *MockFileSystem) SimulateRenameError(path string, err error)
func (*MockFileSystem) SimulateStatError ¶
func (mfs *MockFileSystem) SimulateStatError(path string, err error)
func (*MockFileSystem) SimulateWriteError ¶
func (mfs *MockFileSystem) SimulateWriteError(path string, err error)
func (*MockFileSystem) Stat ¶
func (mfs *MockFileSystem) Stat(name string) (fs.FileInfo, error)
Stat simulates getting file info from the mock filesystem.
func (*MockFileSystem) WalkDir ¶
func (mfs *MockFileSystem) WalkDir(root string, fn fs.WalkDirFunc) error
WalkDir simulates walking the directory structure in the mock filesystem. This is a basic simulation suitable for many tests.
type RealFileSystem ¶
type RealFileSystem struct{}
RealFileSystem implements the FileSystem interface using the standard os package.
func NewRealFileSystem ¶
func NewRealFileSystem() *RealFileSystem
NewRealFileSystem creates a new instance of RealFileSystem.
func (*RealFileSystem) MkdirAll ¶
func (rfs *RealFileSystem) MkdirAll(path string, perm fs.FileMode) error
MkdirAll creates a directory using os.MkdirAll.
func (*RealFileSystem) ReadFile ¶
func (rfs *RealFileSystem) ReadFile(name string) ([]byte, error)
ReadFile reads the named file using os.ReadFile.
func (*RealFileSystem) Remove ¶
func (rfs *RealFileSystem) Remove(name string) error
Remove removes the named file or directory using os.Remove.
func (*RealFileSystem) Rename ¶
func (rfs *RealFileSystem) Rename(oldpath, newpath string) error
Rename renames (moves) a file using os.Rename.
func (*RealFileSystem) Stat ¶
func (rfs *RealFileSystem) Stat(name string) (fs.FileInfo, error)
Stat returns a FileInfo using os.Stat.
func (*RealFileSystem) WalkDir ¶
func (rfs *RealFileSystem) WalkDir(root string, fn fs.WalkDirFunc) error
WalkDir walks the file tree using filepath.WalkDir.