testutil

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: BSD-3-Clause, ISC Imports: 12 Imported by: 0

Documentation

Overview

Package testutil contains common testing helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertContains

func AssertContains[S ~[]V, V comparable](t *testing.T, s S, v V)

AssertContains fails the test if v is not present in s.

func AssertEqual

func AssertEqual(t *testing.T, got, want any)

AssertEqual compares two values and if they differ, fails the test and prints the difference between them.

func AssertErrorType added in v0.1.4

func AssertErrorType(t *testing.T, got, want error)

AssertErrorType asserts that the got error is of the same type as the want error. It does not compare error messages or values, only the types.

func AssertNotContains

func AssertNotContains[S ~[]V, V comparable](t *testing.T, s S, v V)

AssertNotContains fails the test if v is present in s.

func BuildTxtar

func BuildTxtar(t *testing.T, dir string) []byte

BuildTxtar constructs a txtar archive from contents of dir.

func ExtractTxtar

func ExtractTxtar(t *testing.T, ar *txtar.Archive, dir string)

ExtractTxtar extracts a txtar archive to dir.

func MockHTTPClient

func MockHTTPClient(h http.Handler) *http.Client

MockHTTPClient returns a http.Client that serves all requests made through it from handler h.

func Run

func Run(t *testing.T, glob string, f func(t *testing.T, match string))

Run runs a subtest for each file matching the provided glob pattern.

func RunGolden

func RunGolden(t *testing.T, glob string, f func(t *testing.T, match string) []byte, update bool)

RunGolden runs a subtest for each file matching the provided glob pattern, computing the result and comparing it with a golden file, or updating a golden file if update is true.

f is a function that should compute the result and return it as a byte slice.

func UnmarshalJSON

func UnmarshalJSON[V any](t *testing.T, b []byte) V

UnmarshalJSON parses the JSON data into v, failing the test in case of failure.

Types

This section is empty.

Jump to

Keyboard shortcuts

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