Skip to main content

Crate umbral_testing

Crate umbral_testing 

Source
Expand description

umbral-testing — test helpers for umbral apps.

Django’s TestCase + Client ergonomics, in the Rust shape. The repeated work in every plugin’s tests/integration.rs was four things: spin up a fresh sqlite pool, build the router, send requests, read the response. This crate collapses those into:

  • TempPool — a tempfile-backed SQLite pool that’s dropped when the guard goes out of scope.
  • TestClient — wraps an axum::Router with HTTP-verb- shaped methods, a per-client cookie jar (so a session set on one request rides on the next), and JSON helpers.
  • TestResponse — owns the response bytes and headers and exposes assertion helpers (assert_status, body_json, assert_body_contains).

This crate is NOT a plugin. It’s a sibling utility library consumed by test code — drop umbral-testing into a crate’s [dev-dependencies] and you don’t carry it into release builds.

use umbral_testing::{TempPool, TestClient};

#[tokio::test]
async fn list_endpoint_returns_seeded_rows() {
    let pool = TempPool::new().await;
    // ... build router using pool.handle() ...
    let client = TestClient::new(router);
    let resp = client.get("/api/notes").await;
    resp.assert_status_ok();
    let notes: Vec<Note> = resp.body_json();
    assert_eq!(notes.len(), 2);
}

Re-exports§

pub use fake;

Structs§

TempPool
A tempfile-backed SQLite pool. Holding the TempPool keeps the underlying directory alive; dropping it deletes the database file and every WAL artefact alongside.
TestClient
A test client over an axum Router. Stateful: cookies set on one response automatically ride on the next request.
TestResponse
The result of one round trip. Owns the response bytes so the caller can read them more than once (e.g. snapshot the raw body before parsing JSON, then assert).

Enums§

FactoryError
Error from a Factory persistence call.

Traits§

Factory
A factory for producing realistic instances of a model — the factory_boy / FactoryBot shape, in Rust.

Functions§

seq
A process-wide monotonic counter for unique values within a test run. Use it to keep unique columns (slugs, emails, crate names) from colliding across a create_batch: