purwa_testing/lib.rs
1//! Test helpers for Purwa applications and workspace crates.
2//!
3//! ## Default (no extra features)
4//!
5//! Use [`http`] helpers to drive an Axum [`Router`](axum::Router) with Tower’s
6//! [`ServiceExt::oneshot`](tower::ServiceExt::oneshot) without boilerplate. This fits
7//! **inventory** `router_from_inventory()` setups where the router state is `()` (see the
8//! `purwa` / `purwa-core` routing docs).
9//!
10//! **Note:** There is no lightweight official mock for SQLx **`PgPool`**. Fast
11//! tests should avoid constructing a real pool—test handlers that only need routing, or use
12//! [`Extension`] / stub types—**or** run against a real disposable Postgres (below).
13//!
14//! ## Feature **`postgres`**
15//!
16//! Enables **`with_testcontainer_postgres`** (see the **`postgres`** module). **`test_database_url_from_env`**
17//! is always available (see [`mod@env`]). **Do not** duplicate migration logic here: connect with
18//! **`purwa_orm::connect_pool`** and run **`purwa_orm::migrate_up`** / rollbacks the same way as in
19//! **`purwa-orm`** crate integration tests under `purwa-orm/tests/` (e.g. `migrate_integration.rs`).
20//!
21//! Default `cargo test -p purwa-testing` does **not** start Docker; optional tests that need a
22//! container are `#[ignore]`.
23//!
24//! [`Extension`]: axum::Extension
25
26#![forbid(unsafe_code)]
27
28pub mod env;
29pub mod http;
30
31#[cfg(feature = "postgres")]
32pub mod postgres;
33
34pub use env::test_database_url_from_env;
35
36#[cfg(feature = "postgres")]
37pub use postgres::with_testcontainer_postgres;
38
39pub use http::{
40 JsonBodyError, json_body, oneshot, oneshot_body_bytes, oneshot_status,
41 oneshot_status_with_method,
42};