Documentation
¶
Overview ¶
Package hooks defines the testrig lifecycle hook interfaces and configuration.
Index ¶
- Variables
- func CatalogNames() []string
- func RegisterPersistentFlags(fs *pflag.FlagSet)
- func RunEntry(ctx context.Context, flags *pflag.FlagSet, opts RunOptions, shellCmd string, ...) error
- func RunGlobalSetup(ctx context.Context, hook Hook) error
- func RunGlobalSetups(ctx context.Context, flags *pflag.FlagSet, opts RunOptions) error
- func RunGlobalTeardown(ctx context.Context, hook Hook) error
- func RunGlobalTeardowns(ctx context.Context, flags *pflag.FlagSet, opts RunOptions) error
- func RunIterationSetup(ctx context.Context, hook Hook) error
- func RunIterationTeardown(ctx context.Context, hook Hook) error
- type Entry
- type Hook
- type IterationShellCommand
- type Option
- type Phase
- type RunOptions
- type RunOrder
- type Scope
Constants ¶
This section is empty.
Variables ¶
var Catalog = []Entry{ { Name: "GlobalSetup", Flag: "global-setup", Scope: ScopeGlobal, Phase: PhaseSetup, FlagUsage: "Shell command to run before tests", }, { Name: "GlobalTeardown", Flag: "global-teardown", Scope: ScopeGlobal, Phase: PhaseTeardown, FlagUsage: "Shell command to run after tests", }, { Name: "IterationSetup", Flag: "iteration-setup", Scope: ScopeIteration, Phase: PhaseSetup, FlagUsage: "Shell command to run before each diagnose iteration", }, { Name: "IterationTeardown", Flag: "iteration-teardown", Scope: ScopeIteration, Phase: PhaseTeardown, FlagUsage: "Shell command to run after each diagnose iteration", }, }
Catalog is the single source of truth for lifecycle hooks. Add an Entry here to get a CLI flag, config binding (iteration scope), and docs row (via go generate).
Functions ¶
func CatalogNames ¶
func CatalogNames() []string
CatalogNames returns Option registrar names in catalog order.
func RegisterPersistentFlags ¶
RegisterPersistentFlags adds every catalog entry as a root persistent string flag.
func RunEntry ¶
func RunEntry( ctx context.Context, flags *pflag.FlagSet, opts RunOptions, shellCmd string, e Entry, order RunOrder, ) error
RunEntry runs native and/or shell hooks for one catalog entry.
func RunGlobalSetup ¶
RunGlobalSetup runs hook before tests execute. A nil hook is a no-op.
func RunGlobalSetups ¶
RunGlobalSetups runs all global setup hooks (native then shell per entry).
func RunGlobalTeardown ¶
RunGlobalTeardown runs hook after tests execute. A nil hook is a no-op.
func RunGlobalTeardowns ¶
RunGlobalTeardowns runs all global teardown hooks (shell then native per entry).
func RunIterationSetup ¶
RunIterationSetup runs hook before a single diagnose iteration. A nil hook is a no-op.
Types ¶
type Entry ¶
type Entry struct {
Name string // e.g. GlobalSetup; matches testrig.GlobalSetup and RunOptions field.
Flag string // e.g. global-setup (persistent root flag, no leading dashes).
Scope Scope
Phase Phase
FlagUsage string // Cobra flag description.
}
Entry describes one lifecycle hook in the catalog: public Option name, CLI flag, and scope.
func EntryByName ¶
EntryByName returns a catalog entry by Option/func name.
type Hook ¶
Hook is a lifecycle callback. The context carries cancellation from the test runner — hooks should respect it for long-running operations.
func BuildIterationHook ¶
func BuildIterationHook(opts RunOptions, shell IterationShellCommand, phase Phase) Hook
BuildIterationHook composes iteration setup or teardown hooks for diagnose. Returns nil when no native or shell hooks are configured for that phase.
func NewShellHook ¶
NewShellHook returns a Hook that runs cmd via the system shell (sh -c). The hook respects context cancellation. On non-zero exit, the combined stdout+stderr is included in the returned error so failing setup commands are diagnosable.
type IterationShellCommand ¶
IterationShellCommand resolves a shell command for an iteration-scoped entry from flag values.
type Option ¶
type Option func(*runnerOptions)
Option configures the testrig CLI runner.
func GlobalSetup ¶
GlobalSetup registers a hook to run once before any tests.
func GlobalTeardown ¶
GlobalTeardown registers a hook to run once after all tests finish.
func IterationSetup ¶
IterationSetup registers a hook to run before each diagnose iteration.
func IterationTeardown ¶
IterationTeardown registers a hook to run after each diagnose iteration.
type RunOptions ¶
type RunOptions struct {
GlobalSetup Hook
GlobalTeardown Hook
IterationSetup Hook
IterationTeardown Hook
}
RunOptions contains the evaluated configuration for the testrig CLI. It is exported for internal use by the CLI engine.
func BuildOptions ¶
func BuildOptions(opts ...Option) RunOptions
BuildOptions evaluates the functional options and returns the internal struct. It is exported for internal use by the CLI engine.
func (RunOptions) Hook ¶
func (o RunOptions) Hook(name string) Hook
Hook returns the native hook registered for name, or nil.