Module testing

Module testing 

Source
Expand description

Deterministic replay testing framework.

This module provides a TestContext and associated mocking infrastructure that enables reproducible tests by mocking external dependencies such as time, HTTP requests, random number generation, and filesystem operations.

§Overview

The framework extends the existing Context with pluggable providers, allowing tests to inject mocks while production code uses real implementations.

§Example

use xerv_core::testing::{TestContextBuilder, MockClock, MockHttp};
use serde_json::json;

#[tokio::test]
async fn test_order_flow() {
    let ctx = TestContextBuilder::new()
        .with_fixed_time("2024-01-15T10:30:00Z")
        .with_mock_http(
            MockHttp::new()
                .on_post("https://api.stripe.com/charges")
                .respond_json(200, json!({"id": "ch_123", "status": "succeeded"}))
        )
        .with_seed(42)
        .with_sequential_uuids()
        .with_recording()
        .build()
        .unwrap();

    // Execute flow with test context
    // Assert on outputs and recorded events
}

Re-exports§

pub use chaos::ChaosConfig;
pub use chaos::ChaosEngine;
pub use chaos::ChaosFault;
pub use context::TestContext;
pub use context::TestContextBuilder;
pub use providers::ClockProvider;
pub use providers::EnvProvider;
pub use providers::FsProvider;
pub use providers::HttpProvider;
pub use providers::HttpResponse;
pub use providers::MockClock;
pub use providers::MockEnv;
pub use providers::MockFs;
pub use providers::MockHttp;
pub use providers::MockHttpRule;
pub use providers::MockRng;
pub use providers::MockSecrets;
pub use providers::MockUuid;
pub use providers::RealClock;
pub use providers::RealEnv;
pub use providers::RealFs;
pub use providers::RealHttp;
pub use providers::RealRng;
pub use providers::RealUuid;
pub use providers::RngProvider;
pub use providers::SecretsProvider;
pub use providers::UuidProvider;
pub use recording::EventRecorder;
pub use recording::RecordedEvent;
pub use snapshot::assert_snapshot;

Modules§

chaos
Chaos testing utilities.
context
Test context and builder for deterministic testing.
providers
Provider traits and implementations for the testing framework.
recording
Event recording for test replay and debugging.
snapshot
Snapshot testing utilities.