plugintest

package
v3.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(ctx context.Context, fn Func, args ...any) (any, error)

Call executes a Func with context propagation and returns its result. It is context-aware so tests can pass deadlines/logging through the same surface the runtime uses.

func MustCall

func MustCall(t tb, fn Func, args ...any) any

MustCall executes a Func and fails the test on error, letting assertions focus on return values rather than plumbing.

Types

type Author

type Author = plugins.Author

Re-exports public plugin API for tests.

type Func

type Func = plugins.Func

Re-exports public plugin API for tests.

func Decorate

func Decorate(base Func, decorator func(Func) Func) Func

Decorate wraps base with decorator while preserving the canonical signature. In tests this is useful to assert decoration order or to inject spies.

func LookupFunc

func LookupFunc(reg Registry, name string) (Func, bool)

LookupFunc fetches a Func from a Registry by name for assertion or invocation without reaching into registry internals.

func MustLookupFunc

func MustLookupFunc(t tb, reg Registry, name string) Func

MustLookupFunc fetches a function by name or fails the test immediately, avoiding repetitive error handling in plugin specs tests.

func Wrap

func Wrap(fn any) Func

Wrap converts a testing helper or plugin-style function into the canonical Func so tests can exercise callbacks without rewriting them. It accepts common shapes used in plugins and falls back to reflection with context injection, rejecting mismatched arity or types with clear errors.

type FuncSpec

type FuncSpec = plugins.FuncSpec

Re-exports public plugin API for tests.

type FunctionInfo

type FunctionInfo = plugins.FunctionInfo

Re-exports public plugin API for tests.

type Invocation

type Invocation struct {
	Args   []any
	Result any
	Err    error
}

Invocation captures a single call to a spied function, including arguments and results, so tests can assert call order and data.

type Plugin

type Plugin = plugins.Plugin

Re-exports public plugin API for tests.

func NewPlugin

func NewPlugin(info PluginInfo, providers ...SpecProvider) Plugin

NewPlugin forwards to plugins.NewPlugin for fixtures that prefer the full Plugin object instead of raw registry calls.

type PluginInfo

type PluginInfo = plugins.PluginInfo

Re-exports public plugin API for tests.

type PluginWithFuncs

type PluginWithFuncs = plugins.PluginWithFuncs

Re-exports public plugin API for tests.

type Registry

type Registry = plugins.Registry

Re-exports public plugin API for tests.

type SpecList

type SpecList = plugins.SpecList

Re-exports public plugin API for tests.

type SpecProvider

type SpecProvider = plugins.SpecProvider

Re-exports public plugin API for tests.

func Specs

func Specs(specs ...FuncSpec) SpecProvider

Specs forwards to plugins.Specs so tests can stay within plugintest imports.

type Spy

type Spy struct {
	Calls []Invocation
	// contains filtered or unexported fields
}

Spy records calls to a wrapped plugin Func without altering behavior, enabling verification of decorators or dynamic template helpers.

func NewSpy

func NewSpy(fn plugins.Func) *Spy

NewSpy wraps a Func and stores every invocation in memory for later inspection.

func (*Spy) Decorator

func (s *Spy) Decorator() func(plugins.Func) plugins.Func

Decorator returns a decorator that records calls to the base function, convenient for testing decorator chaining.

func (*Spy) Func

func (s *Spy) Func() plugins.Func

Func returns the wrapped function that records invocations before delegating.

func (*Spy) Reset

func (s *Spy) Reset()

Reset clears recorded calls, useful when multiple scenarios share the same spy.

type TestRegistry

type TestRegistry struct {
	// contains filtered or unexported fields
}

TestRegistry is a lightweight, in-memory Registry implementation dedicated to tests. It mirrors the public contract yet stays free of production-only behavior (sources, trust), letting tests register and look up plugin functions deterministically.

func NewRegistry

func NewRegistry() *TestRegistry

NewRegistry creates an empty TestRegistry with no preloaded plugins.

func NewRegistryWith

func NewRegistryWith(info plugins.PluginInfo, providers ...plugins.SpecProvider) *TestRegistry

NewRegistryWith creates a registry and immediately registers provided plugins, a convenience to keep tests concise.

func (*TestRegistry) AddPlugin

func (r *TestRegistry) AddPlugin(info plugins.PluginInfo, providers []plugins.SpecProvider)

AddPlugin registers plugin specs without applying production priorities. The latest registration for a name wins unless a decorator chains onto an existing function.

func (*TestRegistry) Funcs

func (r *TestRegistry) Funcs() map[string]any

Funcs implements Registry.Funcs and returns a copy safe for mutation in tests.

func (*TestRegistry) Groups

Groups returns plugin info alongside functions to support info-oriented tests.

func (*TestRegistry) Hooks

func (r *TestRegistry) Hooks(group string) []plugins.Func

Hooks returns functions filtered by Group.

func (*TestRegistry) Plugins

func (r *TestRegistry) Plugins(ctx context.Context) []plugins.PluginInfo

Plugins returns shallow-copied plugin metadata for assertions.

Jump to

Keyboard shortcuts

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