Skip to main content

cratefield_testing/
lib.rs

1//! `cratefield-testing`: the conformance kit every Factory Zero module runs
2//! against (issue #9) — fake ports, an in-memory SQLite `Database`, and
3//! request helpers over the axum router with **no network**.
4//!
5//! ```no_run
6//! use cratefield_testing::{conformance, TestHarness, request};
7//!
8//! #[test]
9//! fn my_module_conforms() {
10//!     conformance(Box::new(my_module::MyModule::new()));
11//! }
12//!
13//! #[pollster::test]
14//! async fn join_returns_202() {
15//!     let kit = TestHarness::new(vec![Box::new(my_module::MyModule::new())]);
16//!     let response = request(&kit.router, http::Method::POST,
17//!         "/v1/my-module/join", Some(r#"{"email":"nick@example.com"}"#)).await;
18//!     assert_eq!(response.status, http::StatusCode::ACCEPTED);
19//! }
20//! ```
21
22#![doc = include_str!("../README.md")]
23#![forbid(unsafe_code)]
24
25mod conformance;
26mod dialect;
27mod fakes;
28mod harness;
29#[cfg(feature = "postgres")]
30mod pg;
31mod request;
32mod sidecar;
33
34pub use conformance::{
35    assert_wasm_safe_deps, conformance, conformance_in_process_only, sidecar_parity,
36};
37pub use dialect::Dialect;
38pub use fakes::{
39    EmptyDatabase, FakeCaptcha, FakeDefer, FakeDispatcher, FakeHttpClient, FakeMailer,
40    FakeRateLimiter, FixedClock, MailerMode, MemoryBlob, MemoryKeyValue,
41};
42pub use harness::TestHarness;
43pub use request::{TestResponse, request};
44pub use sidecar::{FakeSidecar, Fault, shared as shared_sidecar};
45
46// The fixed test secret for the kit's Signer — an obvious dummy, never real.
47pub const TEST_HARNESS_SECRET: &str = "cratefield-testing-dummy-secret-0123456789";
48
49// Mirrors cratefield-adapter-postgres's integration-test skip reason.
50const POSTGRES_SKIP_REASON: &str = "start a local postgres:16 \
51     (docker run --rm -e POSTGRES_PASSWORD=postgres -p 5433:5432 postgres:16) \
52     and set FZ_TEST_POSTGRES_URL=postgres://postgres:postgres@127.0.0.1:5433/postgres";