klauthed_testing/lib.rs
1#![deny(unsafe_code)]
2#![deny(missing_docs)]
3#![cfg_attr(
4 not(test),
5 deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::indexing_slicing)
6)]
7
8//! Test utilities for klauthed services.
9//!
10//! A small, focused toolkit that services pull in as a **dev-dependency** to make
11//! unit and integration tests deterministic and terse. It builds directly on the
12//! `klauthed-core` primitives, so test fixtures use the same types as production
13//! code.
14//!
15//! * [`clock`] — a [`FixedClock`] you can pin and advance, plus re-exports of
16//! [`Clock`] / [`Timestamp`].
17//! * [`ids`] — deterministic [`Id<T>`](klauthed_core::id::Id) fixtures from a `u64`
18//! seed ([`seeded_id`], [`nil_id`]).
19//! * [`context`] — a deterministic
20//! [`RequestContext`](klauthed_core::context::RequestContext) builder
21//! ([`test_context`], [`TestContextBuilder`]).
22//! * [`repository`] — a thread-safe in-memory
23//! [`Repository`](klauthed_core::domain::Repository) ([`InMemoryRepository`]).
24//! * [`assertions`] — terse [`DomainError`](klauthed_error::DomainError) assertions
25//! ([`assert_category`], [`assert_code`], and the [`DomainErrorExt`] trait).
26//!
27//! The most-used items are re-exported at the crate root for convenience.
28//!
29//! Out of scope for this first cut (possible future work): mock HTTP servers,
30//! testcontainers / database harnesses, and clock-driven async test runners.
31//!
32//! ```
33//! use klauthed_testing::{fixed_clock, seeded_id, test_context, Clock};
34//! use klauthed_core::id::Id;
35//!
36//! struct User;
37//!
38//! let clock = fixed_clock(1_700_000_000_000);
39//! let user_id: Id<User> = seeded_id(7);
40//! let ctx = test_context();
41//!
42//! assert_eq!(clock.now().unix_millis(), 1_700_000_000_000);
43//! assert_eq!(user_id, seeded_id::<User>(7));
44//! assert_eq!(ctx.request_id(), test_context().request_id());
45//! ```
46
47pub mod assertions;
48pub mod clock;
49pub mod context;
50pub mod error;
51pub mod ids;
52pub mod repository;
53
54pub use assertions::{
55 DomainErrorExt, assert_category, assert_code, assert_http_status, assert_retryable,
56};
57pub use clock::{Clock, FixedClock, Timestamp, epoch_clock, fixed_clock};
58pub use context::{TestContextBuilder, test_context};
59pub use error::TestingError;
60pub use ids::{nil_id, seeded_id};
61pub use repository::InMemoryRepository;