Documentation
¶
Overview ¶
Package commandtest supplies an isolated runtime for business command tests.
Index ¶
- func Preview[Args any, Data any](ctx context.Context, recorder *Recorder, identity command.Identity, ...) (*command.DryRun, error)
- type Execution
- type RecordedFile
- type Recorder
- func (r *Recorder) AssertDryRunMatches(dryRun *command.DryRun)
- func (r *Recorder) AssertScriptConsumed()
- func (r *Recorder) CancelAfterRequest(number int)
- func (r *Recorder) CommandContext(identity command.Identity) command.CommandContext
- func (r *Recorder) DryRunContext(identity command.Identity) command.CommandContext
- func (r *Recorder) ExecutionContext(parent context.Context) context.Context
- func (r *Recorder) Files() []RecordedFile
- func (r *Recorder) InputStageContext(identity command.Identity) command.CommandContext
- func (r *Recorder) ReplyFile(method, path, contentType string, content []byte) *Recorder
- func (r *Recorder) ReplyJSON(method, path string, data any) *Recorder
- func (r *Recorder) ReplyURL(rawURL, contentType string, content []byte) *Recorder
- func (r *Recorder) Requests() []command.RequestView
- func (r *Recorder) ScopeChecks() [][]string
- func (r *Recorder) SetPagination(options command.PaginationOptions)
- func (r *Recorder) SetScopeError(err error)
- func (r *Recorder) URLs() []string
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Execution ¶
type Execution[Data any] struct { Data Data }
Execution is the inspected outcome of one business Execute hook.
func RunWithFlags ¶
func RunWithFlags[Args any, Data any](ctx context.Context, recorder *Recorder, identity command.Identity, definition command.Definition[Args, Data], args *Args, flags ...string) (Execution[Data], error)
RunWithFlags executes a page-returning command with the framework's standard pagination flags.
type RecordedFile ¶
type RecordedFile struct {
Target command.FileTarget
Options command.DownloadOptions
SourceURL string
Artifact command.Artifact
Content []byte
}
RecordedFile is one scripted download committed by the test runtime.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder supplies a restricted CommandContext and records its observable activity.
func (*Recorder) AssertDryRunMatches ¶
AssertDryRunMatches verifies method, path, query, body, count, and order.
func (*Recorder) AssertScriptConsumed ¶
func (r *Recorder) AssertScriptConsumed()
AssertScriptConsumed verifies that every scripted response was used.
func (*Recorder) CancelAfterRequest ¶
CancelAfterRequest injects cancellation immediately after the numbered request succeeds.
func (*Recorder) CommandContext ¶
func (r *Recorder) CommandContext(identity command.Identity) command.CommandContext
CommandContext returns a restricted public command context.
func (*Recorder) DryRunContext ¶
func (r *Recorder) DryRunContext(identity command.Identity) command.CommandContext
DryRunContext returns the network-free context the host gives a DryRun hook.
func (*Recorder) ExecutionContext ¶
ExecutionContext creates a cancellable context observed by scripted requests and pagination waits.
func (*Recorder) Files ¶
func (r *Recorder) Files() []RecordedFile
Files returns copied file downloads in execution order.
func (*Recorder) InputStageContext ¶
func (r *Recorder) InputStageContext(identity command.Identity) command.CommandContext
InputStageContext returns the network-free context the host gives Normalize and Validate. Tests that drive those hooks directly must use it, or a command that calls the API before the high-risk confirmation gate passes its tests and fails only in production.
func (*Recorder) ReplyFile ¶
ReplyFile appends an ordered successful file response with an expected request method and path.
func (*Recorder) ReplyJSON ¶
ReplyJSON appends an ordered successful response with an expected request method and path.
func (*Recorder) Requests ¶
func (r *Recorder) Requests() []command.RequestView
Requests returns copied requests in execution order.
func (*Recorder) ScopeChecks ¶
ScopeChecks returns copied scope preflights in execution order.
func (*Recorder) SetPagination ¶
func (r *Recorder) SetPagination(options command.PaginationOptions)
SetPagination supplies host-owned pagination settings.
func (*Recorder) SetScopeError ¶
SetScopeError makes every subsequent scope preflight return err after recording it.