pub struct Assert {
pub headers: Option<HeaderMap>,
pub status: Option<StatusCode>,
pub json: Option<Option<Value>>,
pub response_time_ms: Option<u64>,
pub log_settings: LogSettings,
}Expand description
Assert uses an internal representation of the http response to assert
against. If the HTTP request was successfully sent, then each field will be
Some, otherwise None.
Fields§
§headers: Option<HeaderMap>The http response header to assert.
status: Option<StatusCode>The http response status to assert.
json: Option<Option<Value>>The http response json body to assert.
response_time_ms: Option<u64>The http response time (in milliseconds) to assert.
log_settings: LogSettingsThe test results output.
Implementations§
Source§impl Assert
impl Assert
Sourcepub async fn new(
response: Option<impl Response>,
response_time_ms: Option<u64>,
log_settings: LogSettings,
) -> Self
pub async fn new( response: Option<impl Response>, response_time_ms: Option<u64>, log_settings: LogSettings, ) -> Self
Creates an Assert instance with an internal representation
of the given response to assert.
Sourcepub fn assert_fn<F>(self, func: F) -> Assert
pub fn assert_fn<F>(self, func: F) -> Assert
Extends the built-in assertions with a custom assertion.
The closure gives access to the Assert instance.
§Example
Grillon::new("https://jsonplaceholder.typicode.com")?
.get("/users")
.assert()
.await
.status(is_between(200, 299))
.assert_fn(|assert| {
assert!(!assert.headers.is_empty());
assert!(assert.status == StatusCode::CREATED);
assert!(assert.json.is_some());
println!("Json response : {:#?}", assert.json);
})
.status(is(StatusCode::CREATED));
Sourcepub fn status<T>(self, expr: Expression<T>) -> Assertwhere
T: StatusCodeDsl<StatusCode>,
pub fn status<T>(self, expr: Expression<T>) -> Assertwhere
T: StatusCodeDsl<StatusCode>,
Asserts the status of the response.
Sourcepub fn json_body<T>(self, expr: Expression<T>) -> Assertwhere
T: JsonBodyDsl<Value>,
pub fn json_body<T>(self, expr: Expression<T>) -> Assertwhere
T: JsonBodyDsl<Value>,
Asserts the json body of the response.
Sourcepub fn json_path<T>(self, path: &str, expr: Expression<T>) -> Assertwhere
T: JsonPathDsl<Value>,
pub fn json_path<T>(self, path: &str, expr: Expression<T>) -> Assertwhere
T: JsonPathDsl<Value>,
Asserts the value found at the given json path.
Sourcepub fn response_time<T>(self, expr: Expression<T>) -> Assert
pub fn response_time<T>(self, expr: Expression<T>) -> Assert
Asserts the response time (in milliseconds).
Sourcepub fn headers<T>(self, expr: Expression<T>) -> Assertwhere
T: HeadersDsl<HeaderMap>,
pub fn headers<T>(self, expr: Expression<T>) -> Assertwhere
T: HeadersDsl<HeaderMap>,
Asserts the headers of the response.
Sourcepub fn header<H, T>(self, header_name: H, expr: Expression<T>) -> Assert
pub fn header<H, T>(self, header_name: H, expr: Expression<T>) -> Assert
Asserts a specific header of the response.