Struct actix_test::TestServer

source ·
pub struct TestServer { /* private fields */ }
Expand description

A basic HTTP server controller that simplifies the process of writing integration tests for Actix Web applications.

See start for usage example.

Implementations§

source§

impl TestServer

source

pub fn addr(&self) -> SocketAddr

Construct test server url

source

pub fn url(&self, uri: &str) -> String

Construct test server url

source

pub fn get(&self, path: impl AsRef<str>) -> ClientRequest

Create GET request.

source

pub fn post(&self, path: impl AsRef<str>) -> ClientRequest

Create POST request.

source

pub fn head(&self, path: impl AsRef<str>) -> ClientRequest

Create HEAD request.

source

pub fn put(&self, path: impl AsRef<str>) -> ClientRequest

Create PUT request.

source

pub fn patch(&self, path: impl AsRef<str>) -> ClientRequest

Create PATCH request.

source

pub fn delete(&self, path: impl AsRef<str>) -> ClientRequest

Create DELETE request.

source

pub fn options(&self, path: impl AsRef<str>) -> ClientRequest

Create OPTIONS request.

source

pub fn request(&self, method: Method, path: impl AsRef<str>) -> ClientRequest

Connect request with given method and path.

source

pub async fn load_body<S>( &mut self, response: ClientResponse<S> ) -> Result<Bytes, PayloadError>
where S: Stream<Item = Result<Bytes, PayloadError>> + Unpin + 'static,

source

pub async fn ws_at( &mut self, path: &str ) -> Result<Framed<impl AsyncRead + AsyncWrite, Codec>, WsClientError>

Connect to WebSocket server at a given path.

source

pub async fn ws( &mut self ) -> Result<Framed<impl AsyncRead + AsyncWrite, Codec>, WsClientError>

Connect to a WebSocket server.

source

pub fn client_headers(&mut self) -> Option<&mut HeaderMap>

Get default HeaderMap of Client.

Returns Some(&mut HeaderMap) when Client object is unique (No other clone of client exists at the same time).

source

pub async fn stop(self)

Stop HTTP server.

Waits for spawned Server and System to shutdown (force) shutdown.

Trait Implementations§

source§

impl Drop for TestServer

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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