xerv_core/testing/
mod.rs

1//! Deterministic replay testing framework.
2//!
3//! This module provides a `TestContext` and associated mocking infrastructure
4//! that enables reproducible tests by mocking external dependencies such as
5//! time, HTTP requests, random number generation, and filesystem operations.
6//!
7//! # Overview
8//!
9//! The framework extends the existing `Context` with pluggable providers,
10//! allowing tests to inject mocks while production code uses real implementations.
11//!
12//! # Example
13//!
14//! ```ignore
15//! use xerv_core::testing::{TestContextBuilder, MockClock, MockHttp};
16//! use serde_json::json;
17//!
18//! #[tokio::test]
19//! async fn test_order_flow() {
20//!     let ctx = TestContextBuilder::new()
21//!         .with_fixed_time("2024-01-15T10:30:00Z")
22//!         .with_mock_http(
23//!             MockHttp::new()
24//!                 .on_post("https://api.stripe.com/charges")
25//!                 .respond_json(200, json!({"id": "ch_123", "status": "succeeded"}))
26//!         )
27//!         .with_seed(42)
28//!         .with_sequential_uuids()
29//!         .with_recording()
30//!         .build()
31//!         .unwrap();
32//!
33//!     // Execute flow with test context
34//!     // Assert on outputs and recorded events
35//! }
36//! ```
37
38pub mod chaos;
39pub mod context;
40pub mod providers;
41pub mod recording;
42pub mod snapshot;
43
44// Re-export main types at module root
45pub use chaos::{ChaosConfig, ChaosEngine, ChaosFault};
46pub use context::{TestContext, TestContextBuilder};
47pub use providers::{
48    ClockProvider, EnvProvider, FsProvider, HttpProvider, HttpResponse, MockClock, MockEnv, MockFs,
49    MockHttp, MockHttpRule, MockRng, MockSecrets, MockUuid, RealClock, RealEnv, RealFs, RealHttp,
50    RealRng, RealUuid, RngProvider, SecretsProvider, UuidProvider,
51};
52pub use recording::{EventRecorder, RecordedEvent};
53pub use snapshot::assert_snapshot;