blocks

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package blocks defines the step-block executor contract shared by every rehearse block kind (bash, hurl, sql, dtql, graphql) plus the registry the runner dispatches through. Executors live in one sub-package per kind.

Index

Constants

View Source
const (
	StatusPass = "pass"
	StatusFail = "fail"
)

Step statuses produced by block executors. The runner adds "skipped-after-failure" for steps it never dispatches.

View Source
const MaxStepOutput = 8 * 1024

MaxStepOutput is the per-step captured-output budget (REQ: bash-block): stdout/stderr beyond 8 KiB is truncated with a note.

Variables

This section is empty.

Functions

func Truncate

func Truncate(output string) string

Truncate caps captured step output at MaxStepOutput bytes, appending a note when anything was cut (REQ: bash-block).

Types

type BinaryDependent

type BinaryDependent interface {
	// RequiredBinary returns the name of the external binary the executor
	// needs on PATH.
	RequiredBinary() string
}

BinaryDependent is implemented by executors that delegate to an external binary (hurl and the hurl-derived graphql). The runner scans a scenario's step kinds upfront, before executing step 1: when a required binary is not on PATH the whole scenario is reported skipped — none of its steps run, including earlier bash steps — with a warning naming the binary; skips do not affect the exit code (REQ: hurl-block, REQ: graphql-block).

type Block

type Block interface {
	// Kind returns the fenced-block info-string kind this executor handles.
	Kind() string
	// Run executes one step. Implementations report failures through the
	// StepResult; the runner recovers panics on their behalf.
	Run(ctx StepCtx) StepResult
}

Block is the executor contract implemented once per block kind.

type Capture

type Capture struct {
	Name  string
	Value string
}

Capture is one name=value pair captured by a step for the scenario's context bag (REQ: context-bag). Order is preserved because the bag is an ordered map.

type Registry

type Registry map[string]Block

Registry maps a block kind to its executor. Fenced blocks whose kind is not registered are not step blocks (documentation blocks are ignored).

func NewRegistry

func NewRegistry(executors ...Block) Registry

NewRegistry builds a Registry from the given executors, keyed by Kind().

type StepCtx

type StepCtx struct {
	// WorkDir is the scenario-scoped temp working directory shared by all
	// steps of one scenario (REQ: scenario-shape).
	WorkDir string
	// Body is the fenced block's verbatim content.
	Body string
	// Params are the info-string key=value parameters (e.g. dsn=..., url=...).
	Params map[string]string
	// Vars is the scenario's context bag as ordered name/value pairs
	// (REQ: context-bag). For bash/sql/dtql the runner has already textually
	// interpolated {{name}} into Body/Params before dispatch; hurl-derived
	// executors (hurl, graphql) instead pass Vars to Hurl as
	// `--variable name=value` flags — no textual interpolation for them.
	Vars []Capture
}

StepCtx carries everything a block executor needs to run one step.

type StepResult

type StepResult struct {
	// Status is StatusPass or StatusFail.
	Status string
	// Detail is the failure diagnostic (empty on pass).
	Detail string
	// Output is the captured stdout/stderr, already truncated to
	// MaxStepOutput via Truncate.
	Output string
	// Captures are the values the step captured for the scenario's context
	// bag, in capture order (REQ: context-bag). The runner merges them into
	// the bag after the step.
	Captures []Capture
}

StepResult is the outcome of running one step.

Directories

Path Synopsis
Package bash implements the ```bash rehearse step block: the block body runs via `bash -euo pipefail` in the scenario's working directory; a non-zero exit fails the step (REQ: bash-block).
Package bash implements the ```bash rehearse step block: the block body runs via `bash -euo pipefail` in the scenario's working directory; a non-zero exit fails the step (REQ: bash-block).
Package directives parses the trailing directive comments shared by the data-oriented rehearse blocks (`sql`, `dtql`): `-- assert-rows: <N>`, `-- assert-row-json: {...}` and `-- capture: <name> = <column>` (REQ: sql-block, REQ: dtql-block, REQ: context-bag), and applies the parsed assertions/captures to a query's result rows.
Package directives parses the trailing directive comments shared by the data-oriented rehearse blocks (`sql`, `dtql`): `-- assert-rows: <N>`, `-- assert-row-json: {...}` and `-- capture: <name> = <column>` (REQ: sql-block, REQ: dtql-block, REQ: context-bag), and applies the parsed assertions/captures to a query's result rows.
Package dtqlblock implements the ```dtql rehearse step block: the block body is a DTQL query document (deserialized by dalgo's dtql package) executed against the SQLite store at `db=<path>` via the dalgo SQLite adapter (dalgo2sqlite), with the same trailing `-- assert-rows:` / `-- assert-row-json:` / `-- capture:` directives as the sql block (REQ: dtql-block).
Package dtqlblock implements the ```dtql rehearse step block: the block body is a DTQL query document (deserialized by dalgo's dtql package) executed against the SQLite store at `db=<path>` via the dalgo SQLite adapter (dalgo2sqlite), with the same trailing `-- assert-rows:` / `-- assert-row-json:` / `-- capture:` directives as the sql block (REQ: dtql-block).
Package fileblock implements evaluation of file assertions parsed from rehearse scenario `### Assert: file` headings.
Package fileblock implements evaluation of file assertions parsed from rehearse scenario `### Assert: file` headings.
Package graphql implements the ```graphql rehearse step block: a GraphQL query with `url=<endpoint>` in the info string, an optional `-- variables: {...}` directive, plus `-- assert-jsonpath: <path> == <json-value>` and `-- capture-jsonpath: <name> = <path>` directives.
Package graphql implements the ```graphql rehearse step block: a GraphQL query with `url=<endpoint>` in the info string, an optional `-- variables: {...}` directive, plus `-- assert-jsonpath: <path> == <json-value>` and `-- capture-jsonpath: <name> = <path>` directives.
Package hurl implements the ```hurl rehearse step block: the block body is verbatim Hurl syntax delegated to the `hurl` binary in test mode — the runner does NOT implement an HTTP client (REQ: hurl-block).
Package hurl implements the ```hurl rehearse step block: the block body is verbatim Hurl syntax delegated to the `hurl` binary in test mode — the runner does NOT implement an HTTP client (REQ: hurl-block).
Package sqlblock implements the ```sql rehearse step block: the block's statement(s) run against the DSN from the info string (v0.3 driver: `sqlite:<path>` via the pure-Go driver already in go.mod), with trailing `-- assert-rows:` / `-- assert-row-json:` / `-- capture:` directives checked against the final statement's result rows (REQ: sql-block).
Package sqlblock implements the ```sql rehearse step block: the block's statement(s) run against the DSN from the info string (v0.3 driver: `sqlite:<path>` via the pure-Go driver already in go.mod), with trailing `-- assert-rows:` / `-- assert-row-json:` / `-- capture:` directives checked against the final statement's result rows (REQ: sql-block).

Jump to

Keyboard shortcuts

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