filesystem

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystem

type FileSystem interface {
	// File operations
	ReadFile(path string) ([]byte, error)
	WriteFile(path string, data []byte, perm fs.FileMode) error
	Remove(path string) error

	// Directory operations
	ReadDir(path string) ([]fs.DirEntry, error)
	MkdirAll(path string, perm fs.FileMode) error

	// Path operations
	Stat(path string) (fs.FileInfo, error)
	Exists(path string) bool
	Getwd() (string, error)

	// File walking
	WalkDir(root string, fn fs.WalkDirFunc) error

	// Glob patterns
	Glob(pattern string) ([]string, error)
}

FileSystem provides an abstraction over file operations for testability

type MockFile

type MockFile struct {
	Content []byte
	Mode    fs.FileMode
	ModTime time.Time
	IsDir   bool
}

MockFile represents a file in the mock filesystem

type MockFileSystem

type MockFileSystem struct {
	// contains filtered or unexported fields
}

MockFileSystem provides in-memory filesystem for testing

func NewMockFileSystem

func NewMockFileSystem() *MockFileSystem

NewMockFileSystem creates a new MockFileSystem

func (*MockFileSystem) AddDir

func (mfs *MockFileSystem) AddDir(path string)

AddDir adds a directory to the mock filesystem

func (*MockFileSystem) AddFile

func (mfs *MockFileSystem) AddFile(path string, content []byte)

AddFile adds a file to the mock filesystem

func (*MockFileSystem) Exists

func (mfs *MockFileSystem) Exists(path string) bool

func (*MockFileSystem) GetFiles

func (mfs *MockFileSystem) GetFiles() map[string]*MockFile

GetFiles returns all files in the mock filesystem (for debugging)

func (*MockFileSystem) Getwd

func (mfs *MockFileSystem) Getwd() (string, error)

func (*MockFileSystem) Glob

func (mfs *MockFileSystem) Glob(pattern string) ([]string, error)

func (*MockFileSystem) MkdirAll

func (mfs *MockFileSystem) MkdirAll(path string, perm fs.FileMode) error

func (*MockFileSystem) PrintTree

func (mfs *MockFileSystem) PrintTree()

PrintTree prints the filesystem tree (for debugging)

func (*MockFileSystem) ReadDir

func (mfs *MockFileSystem) ReadDir(path string) ([]fs.DirEntry, error)

func (*MockFileSystem) ReadFile

func (mfs *MockFileSystem) ReadFile(path string) ([]byte, error)

func (*MockFileSystem) Remove

func (mfs *MockFileSystem) Remove(path string) error

func (*MockFileSystem) SetCurrentDir

func (mfs *MockFileSystem) SetCurrentDir(dir string)

SetCurrentDir sets the current working directory for the mock

func (*MockFileSystem) Stat

func (mfs *MockFileSystem) Stat(path string) (fs.FileInfo, error)

func (*MockFileSystem) WalkDir

func (mfs *MockFileSystem) WalkDir(root string, fn fs.WalkDirFunc) error

func (*MockFileSystem) WriteFile

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

type OSFileSystem

type OSFileSystem struct{}

OSFileSystem implements FileSystem using real OS operations

func NewOSFileSystem

func NewOSFileSystem() *OSFileSystem

NewOSFileSystem creates a new OSFileSystem

func (*OSFileSystem) Exists

func (osfs *OSFileSystem) Exists(path string) bool

func (*OSFileSystem) Getwd

func (osfs *OSFileSystem) Getwd() (string, error)

func (*OSFileSystem) Glob

func (osfs *OSFileSystem) Glob(pattern string) ([]string, error)

func (*OSFileSystem) MkdirAll

func (osfs *OSFileSystem) MkdirAll(path string, perm fs.FileMode) error

func (*OSFileSystem) ReadDir

func (osfs *OSFileSystem) ReadDir(path string) ([]fs.DirEntry, error)

func (*OSFileSystem) ReadFile

func (osfs *OSFileSystem) ReadFile(path string) ([]byte, error)

func (*OSFileSystem) Remove

func (osfs *OSFileSystem) Remove(path string) error

func (*OSFileSystem) Stat

func (osfs *OSFileSystem) Stat(path string) (fs.FileInfo, error)

func (*OSFileSystem) WalkDir

func (osfs *OSFileSystem) WalkDir(root string, fn fs.WalkDirFunc) error

func (*OSFileSystem) WriteFile

func (osfs *OSFileSystem) WriteFile(path string, data []byte, perm fs.FileMode) error

Jump to

Keyboard shortcuts

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