pub struct TestApp { /* private fields */ }Expand description
A booted application, ready to be asked for responses.
Not Send: it holds a thread-local facade scope, and moving it to another
thread would unscope on one and pop on another.
Implementations§
Source§impl TestApp
impl TestApp
Sourcepub fn new(app: Arc<Application>) -> Result<Self>
pub fn new(app: Arc<Application>) -> Result<Self>
Wrap an application your own boot produced.
Takes the booted application rather than booting one, because what a test wants exercised is your bootstrap — its providers, its configuration, its routes — not a generic one this crate could build.
Sourcepub fn app(&self) -> &Arc<Application> ⓘ
pub fn app(&self) -> &Arc<Application> ⓘ
The application, for resolving a service to assert on.
Sourcepub fn resolve<T: Send + Sync + 'static>(&self) -> Result<Arc<T>>
pub fn resolve<T: Send + Sync + 'static>(&self) -> Result<Arc<T>>
Resolve a service — app.resolve::<PostRepository>()?.
Sourcepub fn with_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
Send this header on every subsequent request.
let app = app.with_header("authorization", format!("Bearer {token}"));Sourcepub fn with_token(self, token: impl Display) -> Self
pub fn with_token(self, token: impl Display) -> Self
Authenticate every subsequent request with a bearer token.
Sourcepub async fn get(&self, uri: &str) -> TestResponse
pub async fn get(&self, uri: &str) -> TestResponse
GET uri.
Sourcepub async fn delete(&self, uri: &str) -> TestResponse
pub async fn delete(&self, uri: &str) -> TestResponse
DELETE uri.
Sourcepub async fn post(&self, uri: &str, body: &impl Serialize) -> TestResponse
pub async fn post(&self, uri: &str, body: &impl Serialize) -> TestResponse
POST uri with a JSON body.
Sourcepub async fn put(&self, uri: &str, body: &impl Serialize) -> TestResponse
pub async fn put(&self, uri: &str, body: &impl Serialize) -> TestResponse
PUT uri with a JSON body.
Sourcepub async fn patch(&self, uri: &str, body: &impl Serialize) -> TestResponse
pub async fn patch(&self, uri: &str, body: &impl Serialize) -> TestResponse
PATCH uri with a JSON body.
Sourcepub async fn post_empty(&self, uri: &str) -> TestResponse
pub async fn post_empty(&self, uri: &str) -> TestResponse
POST uri with no body — a form action, a publish, a logout.
Sourcepub fn request(&self, method: Method, uri: &str) -> RequestBuilder
pub fn request(&self, method: Method, uri: &str) -> RequestBuilder
A request builder carrying this harness’s default headers.
For the request the helpers above do not cover — a form encoding, an odd header, a deliberately malformed body.
Sourcepub async fn send(&self, request: Request) -> TestResponse
pub async fn send(&self, request: Request) -> TestResponse
Send a request you built yourself, through the whole kernel.
The real pipeline: global middleware, routing, route middleware, the handler, and the exception renderer. A test that bypassed it would be asserting on something no client can reach.
Auto Trait Implementations§
impl !RefUnwindSafe for TestApp
impl !Send for TestApp
impl !Sync for TestApp
impl !UnwindSafe for TestApp
impl Freeze for TestApp
impl Unpin for TestApp
impl UnsafeUnpin for TestApp
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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> ⓘ
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