GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Why Go
  • Case Studies
  • Use Cases
  • Security
  • Learn
  • Effective Go
  • Go User Manual
  • Standard library
  • Release Notes
  • API
  • Packages
  • Recorded Talks
  • Meetups
  • Conferences

This view

  • Original page
  • New address

GeezerVison is showing pkg.go.dev — fstest package - testing/fstest - Go Packages

Details

  • checked Valid go.mod file

    The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.

  • checked Redistributable license

    Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.

  • checked Tagged version

    Modules with tagged versions give importers more predictable builds.

  • checked Stable version

    When a project reaches major version v1 it is considered stable.

  • Learn more about best practices

Repository

cs.opensource.google/go/go

Links

  • Report a Vulnerability

Documentation ¶

Overview ¶

Package fstest implements support for testing implementations and users of file systems.

Index ¶

  • func TestFS(fsys fs.FS, expected ...string) error
  • type MapFS
    • func (fsys MapFS) Glob(pattern string) ([]string, error)
    • func (fsys MapFS) Lstat(name string) (fs.FileInfo, error)
    • func (fsys MapFS) Open(name string) (fs.File, error)
    • func (fsys MapFS) ReadDir(name string) ([]fs.DirEntry, error)
    • func (fsys MapFS) ReadFile(name string) ([]byte, error)
    • func (fsys MapFS) ReadLink(name string) (string, error)
    • func (fsys MapFS) Stat(name string) (fs.FileInfo, error)
    • func (fsys MapFS) Sub(dir string) (fs.FS, error)
  • type MapFile

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func TestFS ¶

func TestFS(fsys fs.FS, expected ...string) error

TestFS tests a file system implementation. It walks the entire tree of files in fsys, opening and checking that each file behaves correctly. Symbolic links are not followed, but their Lstat values are checked if the file system implements fs.ReadLinkFS. 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.AsType to inspect.

Typical usage inside a test is:

if err := fstest.TestFS(myFS, "file/that/should/be/present"); err != nil {
	t.Fatal(err)
}

Types ¶

type MapFS ¶

type MapFS map[string]*MapFile

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, directories, or symbolic links 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.

func (MapFS) Glob ¶

func (fsys MapFS) Glob(pattern string) ([]string, error)

func (MapFS) Lstat ¶ added in go1.25.0

func (fsys MapFS) Lstat(name string) (fs.FileInfo, error)

Lstat returns a FileInfo describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link.

func (MapFS) Open ¶

func (fsys MapFS) Open(name string) (fs.File, error)

Open opens the named file after following any symbolic links.

func (MapFS) ReadDir ¶

func (fsys MapFS) ReadDir(name string) ([]fs.DirEntry, error)

func (MapFS) ReadFile ¶

func (fsys MapFS) ReadFile(name string) ([]byte, error)

func (MapFS) ReadLink ¶ added in go1.25.0

func (fsys MapFS) ReadLink(name string) (string, error)

ReadLink returns the destination of the named symbolic link.

func (MapFS) Stat ¶

func (fsys MapFS) Stat(name string) (fs.FileInfo, error)

func (MapFS) Sub ¶

func (fsys MapFS) Sub(dir string) (fs.FS, error)

type MapFile ¶

type MapFile struct {
	Data    []byte      // file content or symlink destination
	Mode    fs.FileMode // fs.FileInfo.Mode
	ModTime time.Time   // fs.FileInfo.ModTime
	Sys     any         // fs.FileInfo.Sys
}

A MapFile describes a single file in a MapFS.

Source Files ¶

View all Source files
  • mapfs.go
  • testfs.go
Click to show internal directories.
Click to hide internal directories.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.