fstest

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package fstest runs test suites against a target FS. See fstest.FS() to get started.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FS

func FS(tb testing.TB, options FSOptions)

FS runs file system tests. All FS interfaces from hackpadfs.*FS are tested.

func File

func File(tb testing.TB, options FSOptions)

File runs file tests. All File interfaces from hackpadfs.*File are tested.

func TestBaseChmod

func TestBaseChmod(tb testing.TB, setup TestSetup)

func TestBaseChtimes

func TestBaseChtimes(tb testing.TB, setup TestSetup)

func TestBaseCreate

func TestBaseCreate(tb testing.TB, setup TestSetup)

func TestBaseMkdir

func TestBaseMkdir(tb testing.TB, setup TestSetup)

func TestChmod

func TestChmod(tb testing.TB, setup TestSetup)

Chmod changes the mode of the named file to mode. If the file is a symbolic link, it changes the mode of the link's target. If there is an error, it will be of type *PathError.

A different subset of the mode bits are used, depending on the operating system.

fstest will only check permission bits

func TestChtimes

func TestChtimes(tb testing.TB, setup TestSetup)

Chtimes changes the access and modification times of the named file, similar to the Unix utime() or utimes() functions.

The underlying filesystem may truncate or round the values to a less precise time unit. If there is an error, it will be of type *PathError.

func TestConcurrentCreate

func TestConcurrentCreate(tb testing.TB, setup TestSetup)

func TestConcurrentFileRead

func TestConcurrentFileRead(tb testing.TB, setup TestSetup)

func TestConcurrentFileStat

func TestConcurrentFileStat(tb testing.TB, setup TestSetup)

func TestConcurrentFileWrite

func TestConcurrentFileWrite(tb testing.TB, setup TestSetup)

func TestConcurrentMkdir

func TestConcurrentMkdir(tb testing.TB, setup TestSetup)

func TestConcurrentMkdirAll

func TestConcurrentMkdirAll(tb testing.TB, setup TestSetup)

func TestConcurrentOpenFileCreate

func TestConcurrentOpenFileCreate(tb testing.TB, setup TestSetup)

func TestConcurrentRemove

func TestConcurrentRemove(tb testing.TB, setup TestSetup)

func TestCreate

func TestCreate(tb testing.TB, setup TestSetup)

TestCreate verifies fs.Create().

Create creates or truncates the named file. If the file already exists, it is truncated. If the file does not exist, it is created with mode 0666 (before umask). If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR. If there is an error, it will be of type *PathError.

func TestFileClose

func TestFileClose(tb testing.TB, setup TestSetup)

func TestFileRead

func TestFileRead(tb testing.TB, setup TestSetup)

func TestFileReadAt

func TestFileReadAt(tb testing.TB, setup TestSetup)

func TestFileReadDir

func TestFileReadDir(tb testing.TB, setup TestSetup)

func TestFileSeek

func TestFileSeek(tb testing.TB, setup TestSetup)

func TestFileStat

func TestFileStat(tb testing.TB, setup TestSetup)

func TestFileSync

func TestFileSync(tb testing.TB, setup TestSetup)

func TestFileTruncate

func TestFileTruncate(tb testing.TB, setup TestSetup)

func TestFileWrite

func TestFileWrite(tb testing.TB, setup TestSetup)

func TestFileWriteAt

func TestFileWriteAt(tb testing.TB, setup TestSetup)

func TestMkdir

func TestMkdir(tb testing.TB, setup TestSetup)

TestMkdir verifies fs.Mkdir().

Mkdir creates a new directory with the specified name and permission bits (before umask). If there is an error, it will be of type *PathError.

func TestMkdirAll

func TestMkdirAll(tb testing.TB, setup TestSetup)

MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.

func TestOpen

func TestOpen(tb testing.TB, setup TestSetup)

Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. If there is an error, it will be of type *PathError.

func TestOpenFile

func TestOpenFile(tb testing.TB, setup TestSetup)

OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc.). If the file does not exist, and the O_CREATE flag is passed, it is created with mode perm (before umask). If successful, methods on the returned File can be used for I/O. If there is an error, it will be of type *PathError.

func TestReadFile

func TestReadFile(tb testing.TB, setup TestSetup)

func TestRemove

func TestRemove(tb testing.TB, setup TestSetup)

Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError.

func TestRemoveAll

func TestRemoveAll(tb testing.TB, setup TestSetup)

RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error). If there is an error, it will be of type *PathError.

func TestRename

func TestRename(tb testing.TB, setup TestSetup)

TestRename verifies fs.Rename().

Rename renames (moves) oldpath to newpath. If newpath already exists and is not a directory, Rename replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories. If there is an error, it will be of type *LinkError.

func TestStat

func TestStat(tb testing.TB, setup TestSetup)

Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.

Types

type FSOptions

type FSOptions struct {
	// Name of this test run. Required.
	Name string
	// TestFS sets up the current sub-test and returns an FS. Required if SetupFS is not set.
	// Must support running in parallel with other tests. For a global FS like 'osfs', return a sub-FS rooted in a temporary directory for each call to TestFS.
	// Cleanup should be run via tb.Cleanup() tasks.
	TestFS func(tb testing.TB) SetupFS

	// Setup returns an FS that can prepare files and a commit function. Required of TestFS is not set.
	// When commit is called, SetupFS's changes must be copied into a new test FS (like TestFS does) and return it.
	//
	// In many cases, this is not needed and all preparation can be done with only the TestFS() option.
	// However, in more niche file systems like a read-only FS, it is necessary to commit files to a normal FS, then copy them into a read-only store.
	Setup TestSetup
}

FSOptions contains required and optional settings for running fstest against your FS.

type SetupFS

SetupFS is an FS that supports the baseline interfaces for creating files/directories and changing their metadata. This FS is used to initialize a test's environment.

type TestSetup

type TestSetup interface {
	FS(tb testing.TB) (setupFS SetupFS, commit func() hackpadfs.FS)
}

TestSetup returns a new SetupFS and a "commit" function. SetupFS is used to initialize a test's environment with the necessary files and metadata. commit() creates the FS under test from those setup files.

type TestSetupFunc

type TestSetupFunc func(tb testing.TB) (SetupFS, func() hackpadfs.FS)

TestSetupFunc is an adapter to use a function as a TestSetup.

func (TestSetupFunc) FS

func (fn TestSetupFunc) FS(tb testing.TB) (SetupFS, func() hackpadfs.FS)

FS implements TestSetup

Jump to

Keyboard shortcuts

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