fsnodetesting

package
v0.0.0-...-44c758a Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LeafReadAll

func LeafReadAll(ctx context.Context, t testing.TB, n fsnode.Leaf) []byte

func MakeT

func MakeT(t testing.TB, name string, node T) fsnode.T

MakeT is the inverse of (Walker).WalkContents. It keeps no references to node and its children after it returns.

Types

type InfoT

type InfoT = struct {
	fsnode.FileInfo
	T
}

T, Parent, and Leaf are aliases to improve readability of fixture definitions. InfoT augments T with its FileInfo for tests that want to check mode, size, etc.

type Leaf

type Leaf = []byte

T, Parent, and Leaf are aliases to improve readability of fixture definitions. InfoT augments T with its FileInfo for tests that want to check mode, size, etc.

type Parent

type Parent = map[string]T

T, Parent, and Leaf are aliases to improve readability of fixture definitions. InfoT augments T with its FileInfo for tests that want to check mode, size, etc.

type T

type T = interface{}

T, Parent, and Leaf are aliases to improve readability of fixture definitions. InfoT augments T with its FileInfo for tests that want to check mode, size, etc.

type Walker

type Walker struct {
	IgnoredNames map[string]struct{}
	// Info makes WalkContents return InfoT recursively. See that function.
	Info bool
}

Walker is a collection of settings. TODO: Add (Walker).Walk* variant that inspects FileInfo, too, not just content.

func (Walker) WalkContents

func (w Walker) WalkContents(ctx context.Context, t testing.TB, node fsnode.T) T

WalkContents traverses all of node and returns map and []byte objects representing parents/directories and leaves/files, respectively.

For example, if node is a Parent with children named a and b that are regular files, and an empty subdirectory subdir, returns:

Parent{
	"a":      Leaf("a's content"),
	"b":      Leaf("b's content"),
	"subdir": Parent{},
}

If w.Info, the returned contents will include fsnode.FileInfo, for example:

InfoT{
	fsnode.NewDirInfo("parent"),
	Parent{
		"a": InfoT{
			fsnode.NewRegInfo("a").WithSize(11),
			Leaf("a's content"),
		},
		"b": InfoT{
			fsnode.NewRegInfo("b").WithModePerm(0755),
			Leaf("b's content"),
		},
		"subdir": InfoT{
			fsnode.NewDirInfo("subdir")
			Parent{},
		},
	},
}

Jump to

Keyboard shortcuts

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