testseam

package
v1.0.63 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package testseam turns the package-var injection-seam swap into a mechanism instead of a convention. Tests that stub a package-level function var (e.g. pipelineBuildEffectiveRegistry) must use Swap so the previous value is structurally restored via t.Cleanup; a forgotten restore then cannot leak state into sibling tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Protect

func Protect[T any](t *testing.T, ptr *T)

Protect snapshots *ptr and restores it at test end without replacing it. Use it when the code under test mutates the seam itself (e.g. os.Args) and no stub value is available up front. Same sequential-only caveat as Swap.

func Swap

func Swap[T any](t *testing.T, ptr *T, next T)

Swap replaces *ptr with next for the duration of the test and restores the previous value when the test ends. It is the required form for package-var seam swaps:

testseam.Swap(t, &somePackageFn, func(args) (ret, error) { ... })

Prefer it over the manual `prev := fn; t.Cleanup(...); fn = stub` trio: Swap cannot forget the restore. Like the manual pattern it replaces, Swap mutates process-global state and is therefore NOT safe for t.Parallel tests — sequential tests only.

Types

This section is empty.

Jump to

Keyboard shortcuts

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