testcontext

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachDecorator

func AttachDecorator[K comparable](tb testing.TB, key K, decorator func(context.Context) context.Context)

AttachDecorator applies decorator to the test-scoped context once for key. Reusing the same key is a no-op. If the test context does not exist yet, AttachDecorator creates it with the default timeout. Call For with WithTimeout first when using a custom timeout.

func DefaultTimeout

func DefaultTimeout() time.Duration

DefaultTimeout returns the effective default timeout for test-scoped contexts.

func For

func For(tb testing.TB, opts ...Option) context.Context

For returns the test-scoped context for tb. The context is canceled when the test ends or when the configured test timeout expires.

The first call creates the per-test context and fixes its timeout. Later calls return the same context, but an explicit different timeout fails instead of being silently ignored.

Types

type Option

type Option func(*config)

Option configures the test-scoped context returned by For.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets a custom timeout for the test-scoped context.

Jump to

Keyboard shortcuts

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