testutil

package
v0.0.0-...-284ca22 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertGolden

func AssertGolden(t *testing.T, assertionType GoldenAssertion, path string, actual []byte)

AssertGolden is a helper for "golden" or "snapshot" testing. It asserts that `actual`, a serialized YAML document, is equal to the one at `path`. If `-update` has been passed to `go test`, `actual` will be written to `path`.

func Context

func Context(t *testing.T) context.Context

Context returns a context.Context that will cancel 1s before the t's deadline.

func MaybeCleanup

func MaybeCleanup(t *testing.T, fn func())

MaybeCleanup is helper to invoke `fn` within a testing.T.Cleanup closure only if Retain returns false.

func Retain

func Retain() bool

Retain returns the value of the -retain CLI flag. A value of true indicates that cleanup actions should be SKIPPED.

func TempDir

func TempDir(t *testing.T) string

TempDir is wrapper around testing.T.TempDir that respects Retain.

func Update

func Update() bool

Update returns value of the -update CLI flag. A value of true indicates that computed files should be updated instead of asserted against.

Types

type GoldenAssertion

type GoldenAssertion int
const (
	YAML GoldenAssertion = iota
	JSON
	Text
	Bytes
)

type Writer

type Writer struct {
	T *testing.T
}

Writer wraps a testing.T to implement io.Writer by utilizing testing.T.Log.

func (Writer) Write

func (w Writer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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