testutil

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UpdateGolden = flag.Bool("update", false, "update golden files")

Functions

func DiffWithGolden

func DiffWithGolden(t *testing.T, src []byte, golden string)

DiffWithGolden is a test helper that compares the src bytes with a file content whose path is provided in the 'golden' argument. If UpdateGolden flag is true, than the golden file is updated with the provided new content in 'src'.

func DisableLogging

func DisableLogging() (reset func())

DisableLogging is a test helper that disable logging (in fact it sets its level to panic). It returns a function which when called, resets it to its previous level. Its useful to be called as follows in test/benchmarks:

func TestFoo(t *testing.T) {
    defer DisableLogging()()

    // logging is disabled for the whole test
}

func LessLogging

func LessLogging() (reset func())

LessLogging is a test helper that decreases logging (in fact it sets its level to Error). It returns a function which when called, resets it to its previous level. Its useful to be called as follows in test/benchmarks:

func TestFoo(t *testing.T) {
    defer LessLogging()()

    // logging is set to Error for the whole test
}

func NewLogLineFromMap

func NewLogLineFromMap(m map[baker.FieldIndex]string, sep byte) baker.Record

NewLogLineFromMap populates an baker.LogLine with the fields in m.

func TempDir

func TempDir(tb testing.TB) (dir string, rmdir func())

TempDir is a test helper that creates a temporary directory, returns its name and a function which when called removes that directory. This is useful to be called as follows at the top of a test or benchmark requiring a temporary directory:

func TestFoo(t *testing.T) {
    dir, rmdir := testutil.TempDir(t)
    defer rmdir()

    // do something with dir
    ...
}

func TempFile

func TempFile(tb testing.TB) (file string, rmfile func())

TempFile is a test helper that creates a temporary file, returns its name and a function which when called removes that file. This is useful to be called as follows at the top of a test or benchmark requiring a temporary file:

func TestFoo(t *testing.T) {
    name, rmfile := testutil.TempFile(t)
    defer rmfile()

    // do something with filename
    ...
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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