Movatterモバイル変換


[0]ホーム

URL:


fstest

packagestandard library
go1.25.2Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2025 License:BSD-3-ClauseImports:10Imported by:187

Details

Repository

cs.opensource.google/go/go

Links

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcTestFS

func TestFS(fsysfs.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 checkedif the file system implementsfs.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 alist of errors. Useerrors.Is orerrors.As to inspect.

Typical usage inside a test is:

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

Types

typeMapFS

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 containedin the map; those will be synthesized if needed.But a directory can still be included by setting the [MapFile.Mode]'sfs.ModeDir bit;this may be necessary for detailed control over the directory'sfs.FileInfoor 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 concurrentlywith changes to the map, which would be a race.Another implication is that opening or reading a directory requiresiterating over the entire map, so a MapFS should typically be used with not morethan a few hundred entries or directory reads.

func (MapFS)Glob

func (fsysMapFS) Glob(patternstring) ([]string,error)

func (MapFS)Lstatadded ingo1.25.0

func (fsysMapFS) Lstat(namestring) (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 (fsysMapFS) Open(namestring) (fs.File,error)

Open opens the named file after following any symbolic links.

func (MapFS)ReadDir

func (fsysMapFS) ReadDir(namestring) ([]fs.DirEntry,error)

func (MapFS)ReadFile

func (fsysMapFS) ReadFile(namestring) ([]byte,error)

func (MapFS)ReadLinkadded ingo1.25.0

func (fsysMapFS) ReadLink(namestring) (string,error)

ReadLink returns the destination of the named symbolic link.

func (MapFS)Stat

func (fsysMapFS) Stat(namestring) (fs.FileInfo,error)

func (MapFS)Sub

func (fsysMapFS) Sub(dirstring) (fs.FS,error)

typeMapFile

type MapFile struct {Data    []byte// file content or symlink destinationModefs.FileMode// fs.FileInfo.ModeModTimetime.Time// fs.FileInfo.ModTimeSysany// fs.FileInfo.Sys}

A MapFile describes a single file in aMapFS.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp