1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use AppError;
use AnyPool;
use Path;
use OnceCell;
static TEST_DB: = const_new;
/// Connects to a fresh, migrated SQLite database for tests (Rust's own
/// natural test-isolation boundary: `cargo test` already compiles each
/// `tests/*.rs` file as a separate process, so this is one database per
/// test *file*, not per test function - every `#[tokio::test]` fn in the
/// same file shares it).
///
/// Idempotent within a process: the first call creates the database and
/// runs migrations; every later call in the same test binary (i.e. every
/// other `#[tokio::test]` fn in that file) just returns a clone of the
/// already-connected pool, sidestepping `larust_support::orm::connect`'s
/// documented "second call errors" behavior entirely.
///
/// Backed by an on-disk `tempfile` database, not `sqlite::memory:` - a
/// pooled in-memory SQLite database would give each connection its own
/// private, empty database unless opened with SQLite's shared-cache URI
/// mode, which has its own real multi-connection subtleties not worth
/// risking here. The temp directory is intentionally leaked (kept alive
/// for the process's lifetime, not tied to any single test function's
/// stack frame) rather than cleaned up - the OS reclaims temp directories
/// over time, and no test function is a safe place to drop the guard
/// without deleting the database out from under a *different* test
/// function that runs afterward and shares the same pool.
///
/// This is an additive, no-isolation-between-tests tradeoff, not
/// Laravel's `DatabaseTransactions` (a per-test rollback sandbox): every
/// generated `#[derive(Model)]` method and `QueryBuilder` call goes
/// through `larust_orm`'s single process-wide pool directly, with no
/// injectable executor to route a test through its own transaction.
/// Write assertions scoped to the specific rows a test creates, not broad
/// counts across the whole table.
pub async