|
cwist
Modern C web framework with libttak runtime
|
In-process HTTP test client (ala Flask test_client). More...


Go to the source code of this file.
Classes | |
| struct | cwist_test_client_cookie |
| struct | cwist_test_client |
| struct | cwist_test_client_kv |
| A single key/value pair for headers or ad-hoc cookies. More... | |
| struct | cwist_test_client_request_options |
| Optional parameters for advanced test requests. More... | |
Macros | |
Fluent Test Assertions | |
| #define | CWIST_ASSERT_STATUS(res, expected_status) |
| #define | CWIST_ASSERT_HEADER(res, header_name, expected_value) |
| #define | CWIST_ASSERT_BODY_CONTAINS(res, snippet) |
Typedefs | |
| typedef struct cwist_test_client_cookie | cwist_test_client_cookie |
| typedef struct cwist_test_client | cwist_test_client |
| typedef struct cwist_test_client_kv | cwist_test_client_kv |
| A single key/value pair for headers or ad-hoc cookies. | |
| typedef struct cwist_test_client_request_options | cwist_test_client_request_options |
| Optional parameters for advanced test requests. | |
In-process HTTP test client (ala Flask test_client).
Definition in file test_client.h.
Definition at line 170 of file test_client.h.
| #define CWIST_ASSERT_HEADER | ( | res, | |
| header_name, | |||
| expected_value | |||
| ) |
Definition at line 151 of file test_client.h.
| #define CWIST_ASSERT_STATUS | ( | res, | |
| expected_status | |||
| ) |
Definition at line 142 of file test_client.h.
A single key/value pair for headers or ad-hoc cookies.
Optional parameters for advanced test requests.
| void cwist_test_client_clear_cookies | ( | cwist_test_client * | client | ) |
Clear all cookies in the jar.
Clear all cookies in the jar.
| client | Client owning the jar; NULL is a no-op. |
Definition at line 459 of file test_client.c.
References cap, cwist_test_client::cookies, and cwist_test_client_cookie::next.
Referenced by cwist_test_client_destroy().
| cwist_test_client * cwist_test_client_create | ( | cwist_app * | app | ) |
Create a test client for an app.
Create a test client for an app.
| app | App to dispatch requests to; must not be NULL. |
Definition at line 187 of file test_client.c.
References cwist_test_client::app, cap, cwist_test_client::cookies, and cwist_alloc().
| cwist_http_response * cwist_test_client_delete | ( | cwist_test_client * | client, |
| const char * | path | ||
| ) |
Perform a DELETE request.
Perform a DELETE request.
| client | Client to send through. |
| path | Request path. |
Definition at line 346 of file test_client.c.
References cap, and CWIST_HTTP_DELETE.
| void cwist_test_client_destroy | ( | cwist_test_client * | client | ) |
Destroy a test client.
Destroy a test client.
| client | Client to destroy; NULL is a no-op. |
Definition at line 199 of file test_client.c.
References cwist_free(), and cwist_test_client_clear_cookies().
| cwist_http_response * cwist_test_client_get | ( | cwist_test_client * | client, |
| const char * | path | ||
| ) |
Perform a GET request.
Perform a GET request.
| client | Client to send through. |
| path | Request path, optionally containing a "?query" suffix. |
Definition at line 297 of file test_client.c.
References cap, and CWIST_HTTP_GET.
| const char * cwist_test_client_get_cookie | ( | cwist_test_client * | client, |
| const char * | name | ||
| ) |
Get a cookie value from the jar.
Get a cookie value from the jar.
| client | Client owning the jar; NULL yields NULL. |
| name | Cookie name to look up. |
Definition at line 450 of file test_client.c.
References cap, and cwist_test_client::cookies.
| cwist_http_response * cwist_test_client_patch | ( | cwist_test_client * | client, |
| const char * | path, | ||
| const char * | body | ||
| ) |
Perform a PATCH request.
Perform a PATCH request.
| client | Client to send through. |
| path | Request path. |
| body | Null-terminated request body; may be NULL. |
Definition at line 356 of file test_client.c.
References cwist_test_client_request_options::body, and CWIST_HTTP_PATCH.
| cwist_http_response * cwist_test_client_post | ( | cwist_test_client * | client, |
| const char * | path, | ||
| const char * | body | ||
| ) |
Perform a POST request.
Perform a POST request.
| client | Client to send through. |
| path | Request path. |
| body | Null-terminated request body; may be NULL. |
Definition at line 307 of file test_client.c.
References cwist_test_client_request_options::body, and CWIST_HTTP_POST.
| cwist_http_response * cwist_test_client_post_json | ( | cwist_test_client * | client, |
| const char * | path, | ||
| const char * | json_body | ||
| ) |
Perform a POST request with JSON content-type.
Perform a POST request with JSON content-type.
| client | Client to send through. |
| path | Request path. |
| json_body | Null-terminated JSON body; may be NULL. |
Definition at line 320 of file test_client.c.
References cwist_test_client_request_options::body, cap, cwist_test_client_request_options::content_type, and CWIST_HTTP_POST.
| cwist_http_response * cwist_test_client_post_multipart | ( | cwist_test_client * | client, |
| const char * | path, | ||
| const char * | field_name, | ||
| const char * | file_name, | ||
| const char * | content_type, | ||
| const char * | data, | ||
| size_t | data_len | ||
| ) |
Perform a POST request with multipart/form-data body simulating a file upload.
| field_name | Form field name. |
| file_name | File name to report. |
| content_type | MIME type, e.g. "text/plain". |
| data | File contents. |
| data_len | Length of file contents. |
Perform a POST request with multipart/form-data body simulating a file upload.
| client | Client to send through. |
| path | Request path. |
| field_name | Form field name for the file part; must not be NULL. |
| file_name | File name for the Content-Disposition header; must not be NULL. |
| content_type | MIME type of the file data; must not be NULL. |
| data | Raw file bytes; must not be NULL. |
| data_len | Length of data in bytes. |
Definition at line 375 of file test_client.c.
References cwist_test_client::app, cwist_test_client_request_options::body, cwist_test_client_request_options::body_len, cap, cwist_test_client_request_options::content_type, cwist_alloc(), cwist_free(), and CWIST_HTTP_POST.
| cwist_http_response * cwist_test_client_put | ( | cwist_test_client * | client, |
| const char * | path, | ||
| const char * | body | ||
| ) |
Perform a PUT request.
Perform a PUT request.
| client | Client to send through. |
| path | Request path. |
| body | Null-terminated request body; may be NULL. |
Definition at line 334 of file test_client.c.
References cwist_test_client_request_options::body, and CWIST_HTTP_PUT.
| cwist_http_response * cwist_test_client_request_ex | ( | cwist_test_client * | client, |
| cwist_http_method_t | method, | ||
| const char * | path, | ||
| const cwist_test_client_request_options * | opts | ||
| ) |
Perform a request with full control over headers, cookies and query.
Perform a request with full control over headers, cookies and query.
| client | Client to send through. |
| method | HTTP method to use. |
| path | Request path, optionally containing a "?query" suffix. |
| opts | Optional request options (body, headers, content type, ad-hoc cookies). |
Definition at line 286 of file test_client.c.
| void cwist_test_client_set_cookie | ( | cwist_test_client * | client, |
| const char * | name, | ||
| const char * | value, | ||
| const char * | path | ||
| ) |
Set a persistent cookie in the client's cookie jar.
Set a persistent cookie in the client's cookie jar.
| client | Client owning the jar; NULL is a no-op. |
| name | Cookie name; must not be NULL. |
| value | Cookie value; NULL clears the stored value. |
| path | Cookie path; NULL leaves the path unchanged for existing cookies or stores no path for new ones. |
Definition at line 422 of file test_client.c.
References cap, cwist_test_client::cookies, cwist_alloc(), and cwist_free().