labs/mock/api
| Step | Summary |
|---|---|
labs/mock/api/dynamic |
Register a mock that runs steps for every call and answers with what they worked out. |
labs/mock/api/dynamic
Register a mock that runs steps for every call and answers with what they worked out.
It is mock/api in everything but the reply: the same key, the same listener for mock/wait/*, the same published address. Each call runs process on a context of its own — a copy of the run's variables, plus the call as *.request.* — and the reply is read after it, so it can name what the steps published (*.process.<id>.<field>). A step that fails, a reply that cannot be read, or steps slower than process_timeout answer 500. The steps run on the event loop of the run that registered the mock, so they reach the run's services exactly as its other steps do.
Inputs
| Parameter | Type | Required | Default | Also accepts | Description |
|---|---|---|---|---|---|
id |
string | no | '' |
— | Identifier for the registered mock; also the variable its URL is stored under. |
path |
string | yes | — | — | URL path to register, e.g. '/companycertificate/request'. |
method |
string | no | 'POST' |
— | HTTP method the mock answers on. |
api_key_header |
string | no | 'x-api-key' |
— | Request header the run's mock API key must arrive in. |
public |
boolean | no | False |
— | Answer anyone who has the URL, without the API key. Only for a mock an engine step calls that cannot send a header, such as an OAuth2 token endpoint; every other mock requires the key. |
process |
list of StepDefinition | no | [] |
— | Steps run once for every call, in order, before the mock answers — the same shape as the steps nested in 'flow/if'. They read the call as '${{ .request.body }}' (also headers, query, method and path, and any path into them, e.g. '${{ .request.body.header.messageId }}'), and one another's outputs as '${{ *.process. |
response_status |
integer | string | no | 200 |
— | Status code the mock answers with. Read per call, after 'process', so it may be a '${{ *.process. |
response_body |
any | no | {} |
— | JSON body the mock answers with, read per call after 'process': one '${{ *.process. |
response_headers |
object | no | {} |
— | Headers the mock answers with, read per call after 'process'. |
process_timeout |
number | no | 10.0 |
— | Seconds 'process' may take for one call. The caller waits for the reply meanwhile; past this the mock answers 500. |
Output — the value assertions and returns: read
The mock that now exists, and the two URLs a test needs from it.
| Field | Type | Description |
|---|---|---|
mock |
MockInstance | The registered mock, as 'mock/wait/http_request' takes it. |
base_mock_url |
string | Root URL of the testlab mock server. |
full_mock_url |
string | Address to hand the system under test — root plus the mock's path. |
api_key |
string | The key a call must carry — the run's, shared by every mock it registers; empty for a public mock. Hidden unless the step's returns say 'hidden: false'. |
Nested objects
Assertion
Assertion using uses / with verb-form keys.
| Field | Type | Required | Default | Also accepts | Description |
|---|---|---|---|---|---|
cac |
list of string | no | None |
— | |
uses |
string | yes | — | — | |
name |
string | no | None |
— | |
with |
object | no | None |
— |
CheckpointMark
What a test says about a step it marks a checkpoint.
| Field | Type | Required | Default | Also accepts | Description |
|---|---|---|---|---|---|
label |
string | no | None |
— | What the run calls the checkpoint. |
description |
string | no | None |
— | What whoever acts has to do, in a sentence or two. |
direction |
Direction | no | None |
— | 'inbound', 'outbound' or 'internal' — for a step type that declares no checkpoint of its own; 'outbound' when left out. |
via |
Via | no | None |
— | 'direct' or 'dataplane': how the call travels, when it does. |
MockInstance
A registered mock, as the steps that use it later need to see it.
| Field | Type | Required | Default | Also accepts | Description |
|---|---|---|---|---|---|
endpoint_id |
string | no | '' |
— | Identifier the mock was registered under, when it was given one. |
path |
string | yes | — | — | Path the mock listens on. |
method |
string | yes | — | — | HTTP method the mock answers. |
base_mock_url |
string | yes | — | — | Root URL of the testlab mock server. |
full_mock_url |
string | yes | — | — | Address the system under test calls — root plus path. |
ReturnFieldDefinition
Single output field declared in a step returns block.
| Field | Type | Required | Default | Also accepts | Description |
|---|---|---|---|---|---|
type |
string | yes | — | — | |
class |
string | no | None |
— | |
hidden |
boolean | no | None |
— | Mask the value in every record of the run (trace, UI, logs). |
StepDefinition
Step definition using uses and with verb-form keys.
| Field | Type | Required | Default | Also accepts | Description |
|---|---|---|---|---|---|
cac |
list of string | no | None |
— | |
id |
string | no | None |
— | |
uses |
string | yes | — | — | |
name |
string | no | None |
— | |
with |
object | no | None |
— | |
returns |
object | no | None |
— | |
validate |
list of Assertion | no | None |
— | |
expects |
fail |
no | None |
— | |
timeout_s |
number | no | None |
— | |
if |
string | no | None |
— | |
checkpoint |
boolean | CheckpointMark | no | None |
— |