testctx

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package testctx provides a context containing scoped test helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	// T returns the currently in-scope [T].
	T() T

	// Run wraps the [testing.T] Run method, making it mockable.
	Run(name string, fn func(Context))

	// GoMockController returns the [gomock.Controller] relating to the in-scope [T].
	// It memoizes the value for subsequent calls.
	GoMockController() *gomock.Controller

	// Ensure returns the [ensuring.E] relating to the in-scope [T].
	// It returns an interface instead of the concrete type to avoid an import cycle.
	// It memoizes the value for subsequent calls.
	Ensure() interface{}
}

Context contains scoped test helpers.

func New

func New(t T, wrapEnsure WrapEnsure) Context

New creates a new Context.

type T

type T interface {
	Logf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Run(name string, f func(t *testing.T)) bool
	Helper()
	Cleanup(func())
	Parallel()
}

T is a minimal implementation of testing.T that may expand whenever a new method is needed.

type WrapEnsure added in v0.4.1

type WrapEnsure func(T) interface{}

WrapEnsure is a function that returns the [ensuring.E] for the provided T. It returns an interface instead of the concrete type to avoid an import cycle.

Jump to

Keyboard shortcuts

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