fstest

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 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 TestBaseChmod

func TestBaseChmod(tb testing.TB, o FSOptions)

func TestBaseChtimes

func TestBaseChtimes(tb testing.TB, o FSOptions)

func TestBaseCreate

func TestBaseCreate(tb testing.TB, o FSOptions)

func TestBaseMkdir

func TestBaseMkdir(tb testing.TB, o FSOptions)

func TestChmod

func TestChmod(tb testing.TB, o FSOptions)

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, o FSOptions)

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, o FSOptions)

func TestConcurrentFileRead

func TestConcurrentFileRead(tb testing.TB, o FSOptions)

func TestConcurrentFileStat

func TestConcurrentFileStat(tb testing.TB, o FSOptions)

func TestConcurrentFileWrite

func TestConcurrentFileWrite(tb testing.TB, o FSOptions)

func TestConcurrentMkdir

func TestConcurrentMkdir(tb testing.TB, o FSOptions)

func TestConcurrentMkdirAll

func TestConcurrentMkdirAll(tb testing.TB, o FSOptions)

func TestConcurrentOpenFileCreate

func TestConcurrentOpenFileCreate(tb testing.TB, o FSOptions)

func TestConcurrentRemove

func TestConcurrentRemove(tb testing.TB, o FSOptions)

func TestCreate

func TestCreate(tb testing.TB, o FSOptions)

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, o FSOptions)

func TestFileRead

func TestFileRead(tb testing.TB, o FSOptions)

func TestFileReadAt

func TestFileReadAt(tb testing.TB, o FSOptions)

func TestFileReadDir

func TestFileReadDir(tb testing.TB, o FSOptions)

func TestFileSeek

func TestFileSeek(tb testing.TB, o FSOptions)

func TestFileStat

func TestFileStat(tb testing.TB, o FSOptions)

func TestFileSync

func TestFileSync(tb testing.TB, o FSOptions)

func TestFileTruncate

func TestFileTruncate(tb testing.TB, o FSOptions)

func TestFileWrite

func TestFileWrite(tb testing.TB, o FSOptions)

func TestFileWriteAt

func TestFileWriteAt(tb testing.TB, o FSOptions)

func TestMkdir

func TestMkdir(tb testing.TB, o FSOptions)

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, o FSOptions)

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, o FSOptions)

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, o FSOptions)

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 TestReadDir added in v0.1.6

func TestReadDir(tb testing.TB, o FSOptions)

func TestReadFile

func TestReadFile(tb testing.TB, o FSOptions)

func TestRemove

func TestRemove(tb testing.TB, o FSOptions)

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, o FSOptions)

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, o FSOptions)

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, o FSOptions)

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

func TestWriteFile added in v0.1.9

func TestWriteFile(tb testing.TB, o FSOptions)

Types

type Constraints added in v0.1.3

type Constraints struct {
	// FileModeMask disables mode checks on the specified bits. Defaults to checking all bits (0).
	FileModeMask hackpadfs.FileMode
	// AllowErrPathPrefix enables more flexible FS path checks on error values by allowing an undefined path prefix.
	AllowErrPathPrefix bool
}

Constraints limits tests to a reduced set of assertions due to non-standard behavior. Avoid setting any of these.

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

	// Contraints limits tests to a reduced set of assertions. Avoid setting any of these options.
	// For example, setting FileModeMask limits FileMode assertions on a file's Stat() result.
	//
	// NOTE: This MUST NOT be used lightly. Any custom constraints severely impairs the quality of a standardized file system.
	Constraints Constraints

	// ShouldSkip determines if the current test with features defined by 'facets' should be skipped.
	// ShouldSkip() is intended for handling undefined behavior in existing systems outside one's control.
	//
	// NOTE: This MUST NOT be used lightly. Any custom skips severely impairs the quality of a standardized file system.
	ShouldSkip func(facets Facets) bool
	// contains filtered or unexported fields
}

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

type Facets added in v0.1.3

type Facets struct {
	// Name is the full name of the current test
	Name string
}

Facets contains details for the current test. Used in FSOptions.ShouldSkip() to inspect and skip tests that should not apply to this 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 TestData added in v0.1.11

type TestData struct {
	// Skips includes details for every skipped test.
	// Useful for verifying compliance with fstest's standard checks. For instance, os.FS checks (almost) none are skipped.
	Skips []Facets
}

TestData reports metadata from test runs.

func FS

func FS(tb testing.TB, options FSOptions) TestData

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

func File

func File(tb testing.TB, options FSOptions) TestData

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

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