pub struct TestRequest(/* private fields */);
Expand description
Test Request
builder
ⓘ
use scrappy::test::TestRequest;
fn index(req: &HttpRequest) -> Response {
if let Some(hdr) = req.headers().get(header::CONTENT_TYPE) {
Response::Ok().into()
} else {
Response::BadRequest().into()
}
}
let resp = TestRequest::with_header("content-type", "text/plain")
.run(&index)
.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
let resp = TestRequest::default().run(&index).unwrap();
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
Implementations§
Source§impl TestRequest
impl TestRequest
Sourcepub fn with_uri(path: &str) -> TestRequest
pub fn with_uri(path: &str) -> TestRequest
Create TestRequest and set request uri
Sourcepub fn with_hdr<H: Header>(hdr: H) -> TestRequest
pub fn with_hdr<H: Header>(hdr: H) -> TestRequest
Create TestRequest and set header
Sourcepub fn with_header<K, V>(key: K, value: V) -> TestRequestwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue,
pub fn with_header<K, V>(key: K, value: V) -> TestRequestwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue,
Create TestRequest and set header
Sourcepub fn header<K, V>(&mut self, key: K, value: V) -> &mut Selfwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue,
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Selfwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue,
Set a header
Set cookie for this request
Sourcepub fn set_payload<B: Into<Bytes>>(&mut self, data: B) -> &mut Self
pub fn set_payload<B: Into<Bytes>>(&mut self, data: B) -> &mut Self
Set request payload
pub fn take(&mut self) -> TestRequest
Trait Implementations§
Source§impl Default for TestRequest
impl Default for TestRequest
Source§fn default() -> TestRequest
fn default() -> TestRequest
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for TestRequest
impl !RefUnwindSafe for TestRequest
impl !Send for TestRequest
impl !Sync for TestRequest
impl Unpin for TestRequest
impl !UnwindSafe for TestRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more