Skip to main content

boot

Function boot 

Source
pub async fn boot<F>(configure: F)
Expand description

Boot a throwaway app for a test binary: in-memory SQLite, your models and plugins, and a schema derived from those models.

App::build() initialises process-wide state (settings, the ambient pool, the model registry) and panics if it runs twice. Every test file in this repo therefore reinvents the same OnceCell + Mutex dance, and gets it subtly wrong in different ways. This is that dance, once, in the library: the first call builds, every later call is a no-op, so each #[tokio::test] can just say what it needs at the top.

use umbral_testing::{boot, Factory};

#[tokio::test]
async fn a_note_can_be_created() {
    boot(|b| b.model::<Note>()).await;      // safe to call from every test
    let note = NoteFactory::create().await.unwrap();
    assert_eq!(Note::objects().count().await.unwrap(), 1);
}

The closure receives the AppBuilder mid-flight, so plugins, models and settings tweaks all go in there:

boot(|b| b.plugin(AuthPlugin::<AuthUser>::default()).model::<Note>()).await;

The schema is created by create_tables, so it is the models’ schema — no hand-written CREATE TABLE to drift out of sync.

Rows persist for the life of the test binary (one database per process). Tests in the same file share it, so make your fixtures distinct — seq is there for exactly that — or assert on rows you created rather than on global counts.