commandtest

package
v1.0.90 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package commandtest supplies an isolated runtime for business command tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Preview

func Preview[Args any, Data any](ctx context.Context, recorder *Recorder, identity command.Identity, definition command.Definition[Args, Data], args *Args) (*command.DryRun, error)

Preview runs Normalize, Validate, and DryRun with a network-free test context.

Types

type Execution

type Execution[Data any] struct {
	Data Data
}

Execution is the inspected outcome of one business Execute hook.

func Execute

func Execute[Args any, Data any](ctx context.Context, recorder *Recorder, identity command.Identity, definition command.Definition[Args, Data], args *Args) (Execution[Data], error)

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 New

func New(testing testing.TB, responses ...Response) *Recorder

New creates a Recorder with an ordered response script.

func (*Recorder) AssertDryRunMatches

func (r *Recorder) AssertDryRunMatches(dryRun *command.DryRun)

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

func (r *Recorder) CancelAfterRequest(number int)

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

func (r *Recorder) ExecutionContext(parent context.Context) context.Context

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

func (r *Recorder) ReplyFile(method, path, contentType string, content []byte) *Recorder

ReplyFile appends an ordered successful file response with an expected request method and path.

func (*Recorder) ReplyJSON

func (r *Recorder) ReplyJSON(method, path string, data any) *Recorder

ReplyJSON appends an ordered successful response with an expected request method and path.

func (*Recorder) ReplyURL

func (r *Recorder) ReplyURL(rawURL, contentType string, content []byte) *Recorder

ReplyURL appends an ordered successful direct-URL file response.

func (*Recorder) Requests

func (r *Recorder) Requests() []command.RequestView

Requests returns copied requests in execution order.

func (*Recorder) ScopeChecks

func (r *Recorder) ScopeChecks() [][]string

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

func (r *Recorder) SetScopeError(err error)

SetScopeError makes every subsequent scope preflight return err after recording it.

func (*Recorder) URLs

func (r *Recorder) URLs() []string

URLs returns copied direct download URLs in execution order.

type Response

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

Response is one scripted OpenAPI response.

func Fail

func Fail(err error) Response

Fail creates a failed scripted response.

func Respond

func Respond(data any) Response

Respond creates a successful scripted response containing an OpenAPI data object.

func RespondFile

func RespondFile(contentType string, content []byte) Response

RespondFile creates a successful scripted file response.

Jump to

Keyboard shortcuts

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