Assert

Struct Assert 

Source
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: LogSettings

The test results output.

Implementations§

Source§

impl Assert

Source

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.

Source

pub fn assert_fn<F>(self, func: F) -> Assert
where F: for<'a> Fn(&'a 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));
Source

pub fn status<T>(self, expr: Expression<T>) -> Assert

Asserts the status of the response.

Source

pub fn json_body<T>(self, expr: Expression<T>) -> Assert
where T: JsonBodyDsl<Value>,

Asserts the json body of the response.

Source

pub fn json_path<T>(self, path: &str, expr: Expression<T>) -> Assert
where T: JsonPathDsl<Value>,

Asserts the value found at the given json path.

Source

pub fn response_time<T>(self, expr: Expression<T>) -> Assert
where T: TimeDsl<u64>,

Asserts the response time (in milliseconds).

Source

pub fn headers<T>(self, expr: Expression<T>) -> Assert

Asserts the headers of the response.

Source

pub fn header<H, T>(self, header_name: H, expr: Expression<T>) -> Assert

Asserts a specific header of the response.

Trait Implementations§

Source§

impl Clone for Assert

Source§

fn clone(&self) -> Assert

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Assert

§

impl RefUnwindSafe for Assert

§

impl Send for Assert

§

impl Sync for Assert

§

impl Unpin for Assert

§

impl UnwindSafe for Assert

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,