atrg-testing
Test utilities for at-rust-go: mock clients, fake Jetstream, and in-memory test harness.
Part of at-rust-go (atrg) — a batteries-included AT Protocol backend framework for Rust.
What this crate provides
test_state()— builds anAppStatebacked by in-memory SQLite with migrations pre-applied and no outbound network calls.test_app()— returns a ready-to-use(AtrgApp, AppState)pair fortower::ServiceExt::oneshottesting.seed_session()— inserts a fake authenticated session into the test database so handlers that requireAuthUser/RequireAuthwork without an OAuth round-trip.MockAtprotoClient— programmable stub for AT Protocol XRPC calls (get_record,put_record, etc.). Records every call for assertions.FakeJetstream— feeds deterministicJetstreamEvents into youron_eventhandler without touching the network.
Usage
Add atrg-testing as a dev dependency:
[]
= { = "0.1" }
= { = "1", = ["macros", "rt-multi-thread"] }
= { = "0.5", = ["util"] }
= "0.1"
Testing a JSON handler
use ;
use AppState;
use test_state;
use ServiceExt;
async
async
Testing an authenticated handler
use ;
async
Using FakeJetstream
use FakeJetstream;
async
Design philosophy
- Zero network access. Every component is backed by in-memory stores and stubs.
- Deterministic. No randomness, no real clocks unless you opt in.
- Fast. In-memory SQLite +
oneshotmeans sub-millisecond test execution.
Related crates
| Crate | Role |
|---|---|
atrg-core |
AppState and app builder under test |
atrg-auth |
Session types used by seed_session |
atrg-db |
In-memory SQLite pool and migrations |
atrg-stream |
Real Jetstream consumer (replaced by FakeJetstream in tests) |
License
LGPL-3.0-only — see LICENSE.