Skip to main content

TestAppBuilder

Struct TestAppBuilder 

Source
pub struct TestAppBuilder { /* private fields */ }
Expand description

Builder for test applications.

Provides a fluent API for creating test applications with custom routes, services, and configuration.

§Examples

Basic test app:

use armature_testing::TestAppBuilder;
use armature_core::{HttpResponse, Error};

let app = TestAppBuilder::new()
    .with_route("/test", |_req| async {
        Ok(HttpResponse::ok().with_body(b"test".to_vec()))
    })
    .build();

let client = app.client();
let response = client.get("/test").await;
assert_eq!(response.status(), Some(200));

Implementations§

Source§

impl TestAppBuilder

Source

pub fn new() -> Self

Create a new test app builder

Source

pub fn register<T: Provider + Clone + 'static>(self, provider: T) -> Self

Register a provider

Source

pub fn add_module<M: Module>(self, module: M) -> Self

Add a module.

Registers the module’s providers and controllers (recursively, through imports()/re_exports()) via the same ProviderRegistration / ControllerRegistration function pointers Application itself calls, so DI and routes wired by the module are real — not a no-op.

Like Application::register_module, this deduplicates diamond-imported modules: Module::module_type_id() is monomorphized per concrete module type, so it genuinely identifies the concrete module behind a &dyn Module reference (unlike std::any::type_name_of_val, which only ever reports "dyn Module", the trait object’s own type, for every module). A module reachable via two distinct import paths — e.g. a root importing A and B, both of which import shared module S — registers its providers and controllers exactly once.

Module guards are not applied: TestApp’s router dispatch (via TestClient) routes directly against Router, without guard evaluation, so there is nothing here for a guard to scope against.

§Panics

Panics if a controller factory or route registrar returns an error — a misconfigured module should fail the test loudly rather than silently register nothing. Also panics if the import graph nests deeper than WIRE_MODULE_MAX_DEPTH levels — see that constant’s doc comment; with dedup in place this is only a defense-in-depth backstop for pathological non-cyclic graphs, since true cycles now terminate via the visited set.

Source

pub fn with_container(self, container: Container) -> Self

Set custom container

Source

pub fn with_router(self, router: Router) -> Self

Set custom router

Source

pub fn with_route<F, Fut>(self, path: &str, handler: F) -> Self
where F: Fn(HttpRequest) -> Fut + Send + Sync + Clone + 'static, Fut: Future<Output = Result<HttpResponse, Error>> + Send + 'static,

Add a test route with a handler

§Examples
use armature_testing::TestAppBuilder;
use armature_core::HttpResponse;

let app = TestAppBuilder::new()
    .with_route("/api/health", |_req| async {
        Ok(HttpResponse::ok().with_body(b"OK".to_vec()))
    })
    .build();
Source

pub fn build(self) -> TestApp

Build the test application

Trait Implementations§

Source§

impl Default for TestAppBuilder

Source§

fn default() -> Self

Returns the “default value” for a 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<R, D> DepsPresent<D> for R

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Injectable for T
where T: Send + Sync + 'static,

Source§

fn type_id_of() -> TypeId
where Self: Sized,

Returns the TypeId of this type (for internal use)
Source§

fn type_name_of() -> &'static str
where Self: Sized,

Returns the type name for debugging
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> Provider for T
where T: Injectable,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<R, D> VerifyDeps<D> for R

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