wisp/testing
Constants
pub const default_secret_key_base: String
The default secret key base used for test requests. This should never be used outside of tests.
pub const set_header: fn(Request(a), String, String) ->
Request(a)
Set a header on a request.
Examples
let request =
test.request(test.Get, "/", [], <<>>)
|> test.set_header("content-type", "application/json")
request.headers
// => [#("content-type", "application/json")]
Functions
pub fn bit_array_body(response: Response(Body)) -> BitArray
Read the body of a response as a bit string
Panics
This function will panic if the response body is a file and the file cannot be read.
pub fn connect(
path: String,
headers: List(#(String, String)),
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn delete(
path: String,
headers: List(#(String, String)),
body: String,
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn delete_form(
path: String,
headers: List(#(String, String)),
data: List(#(String, String)),
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
The body parameters are encoded as form data and the content-type
header
is set to application/x-www-form-urlencoded
.
pub fn delete_json(
path: String,
headers: List(#(String, String)),
data: Json,
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
The content-type
header is set to application/json
.
pub fn get(
path: String,
headers: List(#(String, String)),
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn head(
path: String,
headers: List(#(String, String)),
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn options(
path: String,
headers: List(#(String, String)),
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn patch(
path: String,
headers: List(#(String, String)),
body: String,
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn patch_form(
path: String,
headers: List(#(String, String)),
data: List(#(String, String)),
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
The body parameters are encoded as form data and the content-type
header is set to application/x-www-form-urlencoded
.
pub fn patch_json(
path: String,
headers: List(#(String, String)),
data: Json,
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
The content-type
header is set to application/json
.
pub fn post(
path: String,
headers: List(#(String, String)),
body: String,
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn post_form(
path: String,
headers: List(#(String, String)),
data: List(#(String, String)),
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
The body parameters are encoded as form data and the content-type
header
is set to application/x-www-form-urlencoded
.
pub fn post_json(
path: String,
headers: List(#(String, String)),
data: Json,
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
The content-type
header is set to application/json
.
pub fn put(
path: String,
headers: List(#(String, String)),
body: String,
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn put_form(
path: String,
headers: List(#(String, String)),
data: List(#(String, String)),
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
The body parameters are encoded as form data and the content-type
header
is set to application/x-www-form-urlencoded
.
pub fn put_json(
path: String,
headers: List(#(String, String)),
data: Json,
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler.
The content-type
header is set to application/json
.
pub fn request(
method: Method,
path: String,
headers: List(#(String, String)),
body: BitArray,
) -> Request(Connection)
Create a test HTTP request that can be used to test your request handler functions.
Note not all HTTP methods are expected to have an accompanying body, so when
using this function directly over other functions such as get
and post
take care to ensure you are not providing a body when it is not expected.
The default_secret_key_base
constant is used as the secret key base for
requests made with this function.
pub fn set_cookie(
req: Request(Connection),
name: String,
value: String,
security: Security,
) -> Request(Connection)
Set a cookie on the request.
pub fn string_body(response: Response(Body)) -> String
Read the body of a response as a string.
Panics
This function will panic if the response body is a file and the file cannot be read, or if it does not contain valid UTF-8.