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
25// Needs only `cratefield-core`, so it is ungated like `vectors` and
26// `tmp`: a light consumer can assert the batch contract without the
27// harness graph (issues #126, #201).
28mod batch;
29#[cfg(feature = "harness")]
30mod conformance;
31#[cfg(feature = "harness")]
32mod dialect;
33#[cfg(feature = "harness")]
34mod fakes;
35#[cfg(feature = "harness")]
36mod harness;
37#[cfg(feature = "postgres")]
38mod pg;
39#[cfg(feature = "port-conformance")]
40mod port;
41#[cfg(feature = "harness")]
42mod request;
43#[cfg(feature = "harness")]
44mod sidecar;
45mod tmp;
46pub mod vectors;
47
48pub use batch::assert_batch_is_atomic;
49#[cfg(feature = "harness")]
50pub use conformance::{conformance, conformance_in_process_only, sidecar_parity};
51#[cfg(feature = "harness")]
52pub use dialect::Dialect;
53#[cfg(feature = "harness")]
54pub use fakes::{
55    EmptyDatabase, FakeCaptcha, FakeDefer, FakeDispatcher, FakeHttpClient, FakeMailer,
56    FakePayments, FakePush, FakeRateLimiter, FakeRealtime, FixedClock, MailerMode, MemoryBlob,
57    MemoryKeyValue, PaymentsCall, PaymentsMode, PushMode,
58};
59#[cfg(feature = "harness")]
60pub use harness::TestHarness;
61#[cfg(feature = "port-conformance")]
62pub use port::{assert_wasm_safe_deps, push_recipient_conformance};
63#[cfg(feature = "harness")]
64pub use request::{TestResponse, request};
65#[cfg(feature = "harness")]
66pub use sidecar::{FakeSidecar, Fault, shared as shared_sidecar};
67pub use tmp::TempDir;
68
69// The fixed test secret for the kit's Signer — an obvious dummy, never real.
70pub const TEST_HARNESS_SECRET: &str = "cratefield-testing-dummy-secret-0123456789";
71
72// Mirrors cratefield-adapter-postgres's integration-test skip reason.
73// The dialect axis (behind `harness`) prints it when the Postgres leg is
74// unavailable, so it exists whenever that axis or the leg itself does.
75#[cfg(any(feature = "harness", feature = "postgres"))]
76const POSTGRES_SKIP_REASON: &str = "start a local postgres:16 \
77     (docker run --rm -e POSTGRES_PASSWORD=postgres -p 5433:5432 postgres:16) \
78     and set FZ_TEST_POSTGRES_URL=postgres://postgres:postgres@127.0.0.1:5433/postgres";