Cassette tests
A cassette is a recorded conversation between a connector and an API: the requests the connector
must send, and the responses the API gives back. tappet connector test <id> runs every cassette
in connectors/<id>/tests/ against a local mock server, so tests are fast, deterministic and need
no credentials.
The canonical format definition is in Node type mapping: cassette format. This page explains how to use it.
How a cassette runs
- The runner loads the connector and builds the node for
operation. - Every outbound request is redirected to a local mock server. The original URL is preserved for matching.
- Requests must arrive in the order of
exchanges. Each request is matched against itsrequestblock; theresponseblock is served back. - After the run, the node output (or error, or trigger state, or webhook response) is compared with
expect. Unused exchanges fail the test, as do unexpected extra requests.
Fields
name: send message to channel # human description, shown in failures
operation: message.post # what to run (see below)
auth: bot_token # auth alternative id
credential: { token: "xoxb-test" } # credential fields
refreshed_credential: { ... } # OAuth2: credential returned after a forced refresh
params: { channel: "C123", text: "hello" }
input: # input items, optional
- json: { id: 1 }
binary:
data: { file_name: a.txt, mime_type: text/plain, text: "hello" } # or base64: "..."
static_data: { ... } # triggers: stored state before the run
webhook: { ... } # webhook triggers: the incoming request
search: "gen" # lookups: search text
cursor: "c2" # lookups: page cursor
exchanges: [ ... ]
expect: { ... }
operation
| Value | Runs |
|---|---|
resource.operation | An operation, once per input item (or once, for per_item: false). |
lookup:<name> | A lookup. Output is the list of { label, value, url? } options. |
trigger:<name> | A poll trigger (one poll), or a webhook trigger receiving webhook. |
trigger:<name>:activate | Webhook trigger activation (check / create lifecycle hooks). |
trigger:<name>:deactivate | Webhook trigger deactivation (delete). |
exchanges
exchanges:
- request:
method: POST
url: https://slack.com/api/chat.postMessage # exact, including the query string
# url_prefix: https://slack.com/api/ # or a prefix
headers: { authorization: "Bearer xoxb-test" } # subset match; names case-insensitive; "*" = present
absent_headers: [cookie] # must not be sent
body_json: { channel: "C123", text: "hello" } # exact JSON
# body_contains: { channel: "C123" } # JSON subset
# body_form: { grant_type: client_credentials } # form fields
# body_text: "raw text" # exact text
# body_multipart_fields: { title: "Report" } # multipart text fields
response:
status: 200 # default 200
headers: { content-type: application/json }
body_json: { ok: true, message: { ts: "1.2", text: "hello" } }
# body: "plain text"
# body_base64: "iVBORw0..." # binary responses
webhook
webhook:
method: POST
headers: { content-type: application/json, X-Signature: "sha256=..." }
query: { token: abc }
body_json: { event: { id: 1 } }
# body: '{"event":{"id":1}}' # exact raw body; use this when a signature covers the bytes
expect
| Key | Asserts |
|---|---|
output | The output items on port 0, in order. The count must match exactly; each item must contain the listed keys and values (extra keys in the actual item are allowed, and a null expected value also matches a missing key). |
error.contains | The run failed and the error message (or its description) contains this text. |
static_data | Subset of the trigger’s stored state after the run (null asserts a key was cleared). |
binary | Binary properties of the first output item (file_name, mime_type, text or base64). |
response_status, response_body | Webhook triggers: the immediate response (handshakes, rejected signatures, filtered events). |
What to test
For each connector:
- Every operation, with realistic parameters, asserting the exact request body. Request bodies are where most connector bugs are.
- Optional parameters left empty, to prove
omit_emptyand defaults work. - Pagination: at least one cassette with two pages and one with
return_all: falseand alimitsmaller than the first page. - Errors: one cassette for the vendor’s error format (asserting the message is extracted), one
for an auth failure, and one for
429withRetry-Afterif the API rate limits. - OAuth2 refresh: a
401followed by a retry withrefreshed_credential. - Each lookup, including
depends_onparameters. - Each trigger: a first poll (emits nothing), a later poll (emits only new entries), webhook
activation and deactivation, a valid signature, an invalid signature (
response_status: 401), and any handshake. - Uploads and downloads:
inputwith a binary property, andexpect.binaryfor downloads.
Writing good cassettes
-
Build responses from the vendor’s documented examples, trimmed to the fields the connector reads plus a few it does not, so tests show that extra fields are tolerated.
-
Use obviously fake values:
xoxb-test,C123,[email protected]. Never paste real tokens, account IDs, names or email addresses. -
One behavior per cassette, with a
namethat says what is being proven. -
For webhook signatures, use
webhook.bodywith the exact bytes, and compute the signature with a throwaway secret:printf '%s' '{"event":{"id":1}}' | openssl dgst -sha256 -hmac 'test-secret' -hex
Running
tappet connector test acme_tasks # all cassettes of one connector
cargo test -p tappet-connect # every connector in the repository
Failures show the cassette name and every mismatch: missing or unexpected requests, request fields that differ, and output items that do not match.