Documentation
¶
Index ¶
- Variables
- type MapFS
- type MapFile
- type MemFS
- type RwMemFS
- func (mfs RwMemFS) Chmod(name string, mode fs.FileMode) error
- func (mfs RwMemFS) Create(name string) (filesys.File, error)
- func (mfs RwMemFS) Mkdir(name string, perm fs.FileMode) error
- func (mfs RwMemFS) MkdirAll(name string, perm fs.FileMode) error
- func (mfs RwMemFS) MkdirTemp(dir, pattern string) (string, error)
- func (mfs RwMemFS) Remove(name string) error
- func (mfs RwMemFS) RemoveAll(name string) error
- func (mfs RwMemFS) Rename(oldName, newName string) error
- func (mfs RwMemFS) TempDir() string
- func (mfs RwMemFS) WriteFile(name string, data []byte, perm fs.FileMode) error
Constants ¶
This section is empty.
Variables ¶
var ( D = Dir() F = File() // EmptyFS is a shared empty MapFS for tests that need an fs.FS with no files. EmptyFS = MapFS{} )
var ErrDirNotEmpty = errors.New("directory not empty")
ErrDirNotEmpty is returned by RwMemFS.Remove when the target directory has children.
Functions ¶
This section is empty.
Types ¶
type MemFS ¶
MemFS implements fs.FS and fmt.Stringer — the read-only view of an in-memory filesystem. It wraps testing/fstest.MapFS, whose underlying map is a reference type. Call NewRwMemFS on a MemFS for the read/write view (RwMemFS) of the same underlying map.
func (MemFS) GetFullPath ¶
GetFullPath returns relpath joined onto the root identifier, matching osfs.FS's GetFullPath semantics closely enough for test code that treats the two interchangeably — an absolute-looking relpath is returned as-is.
func (MemFS) GetRoot ¶
GetRoot returns the root identifier this MemFS was constructed with — there's no real filesystem root to report, so this is just the string passed to NewMemFS (a testcase name or similar identifier).
func (MemFS) NewRwMemFS ¶
NewRwMemFS converts an already-constructed MemFS into its read/write view, sharing the same underlying map — no extra setup, since the map is already a reference type.
type RwMemFS ¶
type RwMemFS struct {
MemFS
}
RwMemFS is MemFS's read/write view: write operations (WriteFile, MkdirAll, Remove, RemoveAll, ...) on top of MemFS's read-only surface. It wraps the same underlying map as the MemFS it was built from — MapFS's underlying map is a reference type, so value-receiver write methods mutate the shared map safely.
func (RwMemFS) Chmod ¶
Chmod changes name's permission bits. name must already have an entry in the map.
func (RwMemFS) Create ¶
Create creates (or truncates) name and returns a writable handle to it. Writes are buffered and committed into the map only on Close.
func (RwMemFS) Mkdir ¶
Mkdir creates the named directory. The parent directory must already exist (explicitly or implicitly), and name must not already exist — mirrors os.Mkdir semantics.
func (RwMemFS) MkdirAll ¶
MkdirAll inserts explicit directory entries for name and each ancestor that is not already present. MapFS synthesises implicit directories, but explicit entries make Remove/RemoveAll semantics predictable and Stat consistent with real FS behaviour.
func (RwMemFS) MkdirTemp ¶
MkdirTemp creates a new directory under dir with a name built from pattern (a trailing "*" in pattern is replaced with a random string; with no "*" the random string is appended) and returns its path. There's no real OS temp semantics here — no auto cleanup — it's just a uniquely named directory entry.
func (RwMemFS) Remove ¶
Remove deletes a single file or empty directory. Returns fs.ErrNotExist if name is absent (no explicit entry and no nested entries). Returns ErrDirNotEmpty if nested entries exist under name.
func (RwMemFS) RemoveAll ¶
RemoveAll deletes name and all entries nested under it. A missing name is not an error (matches zxos.RemoveAll semantics).
func (RwMemFS) Rename ¶
Rename moves oldName — and, if it's a directory, every entry nested under it — to newName within the map. A real key move, not a copy-and-delete, so it's cheap regardless of file size.
func (RwMemFS) TempDir ¶
TempDir creates a new, uniquely-named directory in mfs and returns its path — an in-memory analog of testing.T.TempDir(), for test code that needs a MemFS-backed "temp dir" fixture instead of a real one on disk. No error return: unlike a real MkdirTemp, this can't practically fail (no disk-full, no permissions).