testthings

package module
v0.0.0-...-de5681c Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func C

func C(testingT Cleanuper) context.Context

C provides a context cleaned up with tests. A convenience function.

func FormatKV

func FormatKV(kvFormat string, kv KV) string

FormatKV produces a string with each key-pair formatted with the provided string. Trailing whitespace (and `,`) are treated as formatted string separators and is implicitly used to join the formatted strings together.

func LogKV

func LogKV(testingT Logger, kv KV)

LogKV logs one line per key-pair to provide contextual output within test cases.

func NewContext

func NewContext(testingT Cleanuper) (context.Context, context.CancelFunc)

NewContext creates a context that's cancelled when the testing.TB scope ends.

Types

type Cleanuper

type Cleanuper interface {
	Cleanup(func())
}

Cleanuper describe types that can cleanup after themselves and that allow adding functions to be called when they're cleaning up. In practice, this is really just a scoped-down testing.TB.

type KV

type KV map[string]any

KV is a convenience type to hold, format, and log contextual data. Helpers are available both at the package level and on the type itself.

func (KV) Format

func (k KV) Format(format string) string

Format formats the entire KV into a string. See FormatKV for details on format strings are handled.

func (KV) Log

func (k KV) Log(testingT Logger)

Log prints the KV to the logger, one key-pair on each line.

func (KV) Logf

func (k KV) Logf(testingT Logger, format string)

Log prints the KV to the logger, one key-pair on each line formatted accordint to the given format string.

func (KV) Strings

func (k KV) Strings(format string) []string

Strings returns a list of strings where each key-pair has been formatted. The results are lexicographically sorted by their key.

type Logger

type Logger interface {
	Log(args ...any)
}

Logger describes types that can emit log messages. In practice, this is really just a scoped-down testing.TB.

type Terminator

type Terminator interface {
	Fatal(args ...any)
}

Terminator describes types that can log and terminate the test. In practice, this is really just a scoped-down testing.TB.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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