Skip to main content

Crate klauthed_testing

Crate klauthed_testing 

Source
Expand description

Test utilities for klauthed services.

A small, focused toolkit that services pull in as a dev-dependency to make unit and integration tests deterministic and terse. It builds directly on the klauthed-core primitives, so test fixtures use the same types as production code.

The most-used items are re-exported at the crate root for convenience.

Out of scope for this first cut (possible future work): mock HTTP servers, testcontainers / database harnesses, and clock-driven async test runners.

use klauthed_testing::{fixed_clock, seeded_id, test_context, Clock};
use klauthed_core::id::Id;

struct User;

let clock = fixed_clock(1_700_000_000_000);
let user_id: Id<User> = seeded_id(7);
let ctx = test_context();

assert_eq!(clock.now().unix_millis(), 1_700_000_000_000);
assert_eq!(user_id, seeded_id::<User>(7));
assert_eq!(ctx.request_id(), test_context().request_id());

Re-exports§

pub use assertions::DomainErrorExt;
pub use assertions::assert_category;
pub use assertions::assert_code;
pub use assertions::assert_http_status;
pub use assertions::assert_retryable;
pub use clock::epoch_clock;
pub use clock::fixed_clock;
pub use context::TestContextBuilder;
pub use context::test_context;
pub use error::TestingError;
pub use ids::nil_id;
pub use ids::seeded_id;
pub use repository::InMemoryRepository;

Modules§

assertions
Terse assertions for DomainError values.
clock
Clock helpers for tests.
context
Deterministic RequestContext builders for tests.
error
Error type for the testing utilities (TestingError).
ids
Deterministic identifiers for test fixtures.
repository
A generic in-memory Repository for tests.

Structs§

FixedClock
A controllable clock for tests: pin time to a fixed instant and advance it explicitly. Shareable through &self, so it works behind Arc<dyn Clock>.
Timestamp
A point in time (UTC), the canonical instant type.

Traits§

Clock
A source of the current time.