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.
clock— aFixedClockyou can pin and advance, plus re-exports ofClock/Timestamp.ids— deterministicId<T>fixtures from au64seed (seeded_id,nil_id).context— a deterministicRequestContextbuilder (test_context,TestContextBuilder).repository— a thread-safe in-memoryRepository(InMemoryRepository).assertions— terseDomainErrorassertions (assert_category,assert_code, and theDomainErrorExttrait).
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
DomainErrorvalues. - clock
- Clock helpers for tests.
- context
- Deterministic
RequestContextbuilders for tests. - error
- Error type for the testing utilities (
TestingError). - ids
- Deterministic identifiers for test fixtures.
- repository
- A generic in-memory
Repositoryfor tests.
Structs§
- Fixed
Clock - A controllable clock for tests: pin time to a fixed instant and advance it
explicitly. Shareable through
&self, so it works behindArc<dyn Clock>. - Timestamp
- A point in time (UTC), the canonical instant type.
Traits§
- Clock
- A source of the current time.