Involved Source Filesmapfs.go Package fstest implements support for testing implementations and users of file systems.
Package-Level Type Names (total 2)
/* sort by: | */
A MapFile describes a single file in a [MapFS]. // file content // fs.FileInfo.ModTime // fs.FileInfo.Mode // fs.FileInfo.Sys
A MapFS is a simple in-memory file system for use in tests,
represented as a map from path names (arguments to Open)
to information about the files or directories they represent.
The map need not include parent directories for files contained
in the map; those will be synthesized if needed.
But a directory can still be included by setting the [MapFile.Mode]'s [fs.ModeDir] bit;
this may be necessary for detailed control over the directory's [fs.FileInfo]
or to create an empty directory.
File system operations read directly from the map,
so that the file system can be changed by editing the map as needed.
An implication is that file system operations must not run concurrently
with changes to the map, which would be a race.
Another implication is that opening or reading a directory requires
iterating over the entire map, so a MapFS should typically be used with not more
than a few hundred entries or directory reads.( MapFS) Glob(pattern string) ([]string, error) Open opens the named file.( MapFS) ReadDir(name string) ([]fs.DirEntry, error)( MapFS) ReadFile(name string) ([]byte, error)( MapFS) Stat(name string) (fs.FileInfo, error)( MapFS) Sub(dir string) (fs.FS, error)
MapFS : io/fs.FS
MapFS : io/fs.GlobFS
MapFS : io/fs.ReadDirFS
MapFS : io/fs.ReadFileFS
MapFS : io/fs.StatFS
MapFS : io/fs.SubFS
Package-Level Functions (only one)
TestFS tests a file system implementation.
It walks the entire tree of files in fsys,
opening and checking that each file behaves correctly.
It also checks that the file system contains at least the expected files.
As a special case, if no expected files are listed, fsys must be empty.
Otherwise, fsys must contain at least the listed files; it can also contain others.
The contents of fsys must not change concurrently with TestFS.
If TestFS finds any misbehaviors, it returns either the first error or a
list of errors. Use [errors.Is] or [errors.As] to inspect.
Typical usage inside a test is:
if err := fstest.TestFS(myFS, "file/that/should/be/present"); err != nil {
t.Fatal(err)
}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.