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
impl TestAppBuilder
Sourcepub fn add_module<M: Module>(self, module: M) -> Self
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.
Sourcepub fn with_container(self, container: Container) -> Self
pub fn with_container(self, container: Container) -> Self
Set custom container
Sourcepub fn with_router(self, router: Router) -> Self
pub fn with_router(self, router: Router) -> Self
Set custom router
Sourcepub fn with_route<F, Fut>(self, path: &str, handler: F) -> Selfwhere
F: Fn(HttpRequest) -> Fut + Send + Sync + Clone + 'static,
Fut: Future<Output = Result<HttpResponse, Error>> + Send + 'static,
pub fn with_route<F, Fut>(self, path: &str, handler: F) -> Selfwhere
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();