fileloader

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package fileloader loads test.Test values from files containing test inputs and expected outputs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadContent

func LoadContent(name string, f fs.File) (loader.Content, error)

LoadContent is the default ContentLoader implementation.

Types

type ContentLoader

type ContentLoader func(name string, f fs.File) (loader.Content, error)

A ContentLoader is a function that returns content read from a file.

name is the "effective" or "sanitized" name of the file, after any special characters have been removed by the loader. For example, a leading underscore. The f.Stat() method can be used to get the actual file name.

If the returned content's role is loader.NoRole, it is ignored.

type LoadOption

type LoadOption func(*loadOptions)

LoadOption is an option that changes the behavior of a Loader.

func WithFS

func WithFS(f fs.FS) LoadOption

WithFS is a LoadOption that configures an alternative filesystem to use when loading tests.

func WithFileLoader

func WithFileLoader(load ContentLoader) LoadOption

WithFileLoader is a LoadOption that configures an alternative [FileLoader] used to identify test files and load their content.

func WithRecursion

func WithRecursion(on bool) LoadOption

WithRecursion if a LoadOption that enables or disables recursive scanning of sub-directories.

Recursion is enabled by default.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader loads test.Test values from files containing test inputs and expected outputs.

func NewLoader

func NewLoader(options ...LoadOption) *Loader

NewLoader returns a new Loader, which loads golden file tests from the filesystem.

func (*Loader) Load

func (l *Loader) Load(dir string, options ...LoadOption) (test.Test, error)

Load returns a test built from files in the given directory.

Any directory or file that begins with an underscore produces a test that is marked as skipped.

Jump to

Keyboard shortcuts

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