1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! # modo::testing
//!
//! In-process test harness for modo applications.
//!
//! **Requires feature `test-helpers`.** This is the only runtime feature modo
//! ships — it gates every item in this module along with the in-memory /
//! stub backends that tests rely on. Enable it as a dev-dependency:
//!
//! ```toml
//! [dev-dependencies]
//! modo-rs = { version = "0.11.0", features = ["test-helpers"] }
//! ```
//!
//! Integration test files that import from `modo::testing` should guard
//! their contents:
//!
//! ```rust,ignore
//! #![cfg(feature = "test-helpers")]
//! ```
//!
//! The helpers dispatch requests in-process through Tower's
//! [`oneshot`](tower::ServiceExt::oneshot), so no sockets are opened and no
//! runtime server is spawned.
//!
//! # Provides
//!
//! - [`TestApp`] / [`TestAppBuilder`] — assemble a test application with
//! routes, services, and middleware; dispatch requests via HTTP-method
//! helpers (`get`, `post`, `put`, `patch`, `delete`, `options`, `request`).
//! - [`TestDb`] — in-memory libsql database with chainable [`exec`](TestDb::exec)
//! / [`migrate`](TestDb::migrate) setup; exposes a
//! [`Database`](crate::db::Database) handle via [`db()`](TestDb::db).
//! - [`TestPool`] — in-memory [`DatabasePool`](crate::db::DatabasePool) with
//! chainable [`exec`](TestPool::exec) setup; both the default database and
//! all shards use `:memory:`.
//! - [`TestRequestBuilder`] — fluent builder for a single in-process HTTP
//! request with JSON, form, raw-body, and header helpers.
//! - [`TestResponse`] — captured response with status, header, text, JSON,
//! and raw-bytes accessors.
//! - [`TestSession`] — session infrastructure for integration tests: creates
//! the `authenticated_sessions` table (see [`TestSession::SCHEMA_SQL`] and
//! [`TestSession::INDEXES_SQL`]), signs cookies, and builds a
//! [`CookieSessionLayer`](crate::auth::session::CookieSessionLayer).
//!
//! # Quick start
//!
//! ```rust,no_run
//! # #[cfg(feature = "test-helpers")]
//! # async fn example() {
//! use modo::testing::{TestApp, TestDb};
//! use axum::routing::get;
//!
//! async fn hello() -> &'static str { "hello" }
//!
//! let app = TestApp::builder()
//! .route("/", get(hello))
//! .build();
//!
//! let res = app.get("/").send().await;
//! assert_eq!(res.status(), 200);
//! assert_eq!(res.text(), "hello");
//! # }
//! ```
pub use ;
pub use TestDb;
pub use TestPool;
pub use TestRequestBuilder;
pub use TestResponse;
pub use TestSession;