filesystem

package
v0.0.0-...-d811bac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2025 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

--- START OF FILE internal/filesystem/mock_filesystem.go ---

Index

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

type MockFileSystem struct {
	mock.Mock
	// contains filtered or unexported fields
}

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) Chtimes

func (mfs *MockFileSystem) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes simulates changing modification times.

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.

func (*MockFileSystem) WriteFile

func (mfs *MockFileSystem) WriteFile(name string, data []byte, perm fs.FileMode) error

WriteFile simulates writing a file to the mock filesystem.

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) Chtimes

func (rfs *RealFileSystem) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes changes the modification time using os.Chtimes.

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.

func (*RealFileSystem) WriteFile

func (rfs *RealFileSystem) WriteFile(name string, data []byte, perm fs.FileMode) error

WriteFile writes data to the named file using os.WriteFile.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL