filetest

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package filetest helps in verifying that content written to arbitrary io.Writers match some expected content in testdata files.

See the test TestExample for an example of how to use this package.

Index

Constants

View Source
const ExampleStdout = exampleWriter(0)

ExampleStdout is a dumb wrapper around os.Stdout that removes trailing spaces from each line in each io.Writer.Write call. This is useful for examples where os.Stdout output is matched against some output text in comments. However, gofmt trims trailing spaces in the go source code, which means it's impossible to match trailing spaces without trimming in a wrapper like this.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter func([]byte) []byte

Filter represents a byte filter; similar to an UNIX pipe.

type Target

type Target struct {
	Buffer  *bytes.Buffer
	Filters []Filter
}

Target is a write target for arbitrary content sources. Before verifying that the written content is right, the filters are applied in orders on the buffered content.

func (*Target) Filter

func (b *Target) Filter(filter Filter) *Target

Filter adds a new filter to the Target.

func (*Target) Writer

func (b *Target) Writer() io.Writer

Writer returns the io.Writer which content sources can write to. The io.Writer is/writes to the buffer.

type Tester

type Tester struct {
	G *goldie.Goldie
	T *testing.T
	// Files map a file name (conventionally under testdata/) to a
	// target buffer and set of filters.
	Files map[string]*Target
}

Tester is a high-level primitive for goldie.Goldie. It allows registering testdata files to verify io.Writer writes.

func New

func New(t *testing.T, opts ...goldie.Option) *Tester

New is a wrapper for goldie.New, but returns a *Tester goldie helper.

func (*Tester) Add

func (g *Tester) Add(name string) *Target

Add adds a new file target to the Files map. If name already exists in the map, it is overwritten.

func (*Tester) Assert

func (g *Tester) Assert()

Assert verifies the all golden files are up-to-date. All file verifications are run in separate sub-tests.

If the "-update" flag is passed to "go test", for example as "go test . -update", the files under testdata/ will be automatically updated.

func (*Tester) Update

func (g *Tester) Update()

Update updates all file content to match the written bytes to the returned io.Writer.

Jump to

Keyboard shortcuts

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