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
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();Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for TestAppBuilder
impl !UnwindSafe for TestAppBuilder
impl Freeze for TestAppBuilder
impl Send for TestAppBuilder
impl Sync for TestAppBuilder
impl Unpin for TestAppBuilder
impl UnsafeUnpin for TestAppBuilder
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> Injectable for T
impl<T> Injectable for T
Source§fn type_id_of() -> TypeIdwhere
Self: Sized,
fn type_id_of() -> TypeIdwhere
Self: Sized,
Returns the TypeId of this type (for internal use)
Source§fn type_name_of() -> &'static strwhere
Self: Sized,
fn type_name_of() -> &'static strwhere
Self: Sized,
Returns the type name for debugging