TEST @response
Test files only
This directive applies only inside HTTP blocks of test files run by the SQL test runner (npgsqlrest --test).
Capture this HTTP block's response into a temp table with a custom name, instead of the default.
Default naming
Without the directive, the response table name comes from TestRunner.ResponseTempTable:
- a file with one HTTP block →
_response - a file with two or more blocks →
_response_1,_response_2, … in block order
Includes participate in the numbering: HTTP blocks spliced in by \i/\ir count as if pasted.
Syntax
sql
sql
/*
POST /api/login
Content-Type: application/json
# @response login_result
{"email": "ada@example.com", "password": "secret"}
*/
select (select status from login_result) = 200, 'login succeeds';
select (select body::jsonb ->> 'role' from login_result) = 'admin', 'role returned';The named table has the same columns as the default (status int, body text, content_type text, headers jsonb, is_success boolean — configurable).
Notes
- Each block's table is created fresh (no
IF NOT EXISTS): reusing a name — two blocks both saying# @response x, or a name colliding with the default — fails the test loudly rather than silently overwriting. - Named tables make multi-call tests readable:
login_result,created,after_deletebeat_response_1..3. // @responseis accepted as an alternative to# @response.
Related
- TEST @claim — the other HTTP block directive
- Test Runner configuration — table name and column configuration
- Testing Guide