Depot.Test
Depot.Test: test-scoped transaction isolation for Depot.
Wraps Depot.Repo operations in a sandbox that snapshots Vault tables before each test and restores them after, providing clean rollback without a real database.
Usage:
Depot.Test.start_sandbox()
-- Before each test: Depot.Test.checkout(["users", "posts"])
-- ... run test, insert/update/delete via Depot.Repo ...
-- After each test: Depot.Test.checkin()
Depot.Test.stop_sandbox()
Or use the convenience wrapper:
Depot.Test.sandboxed(["users"], fn () -> Depot.Repo.insert(schema, gate) -- assertions ... )
Functions
Start the test sandbox. Call once at the beginning of a test suite. Enables checkout/checkin lifecycle for test isolation.
Depot.Test.start_sandbox()
Checkpoint (snapshot) the current state of the given schema tables. Call before each test to save state for later rollback.
tables is a list of table name strings matching your schemas.
Depot.Test.checkout(["users", "posts"])
Roll back all sandboxed tables to their checkout snapshot. Call after each test to undo any writes.
Depot.Test.checkin()
Stop the sandbox. Call at the end of a test suite.
Depot.Test.stop_sandbox()
Run a function inside a sandbox transaction. Automatically checkpoints the given tables, runs the function, then rolls back regardless of success or failure.
Depot.Test.sandboxed(["users"], fn () -> Depot.Repo.insert(schema, gate) -- ... test assertions ... )
Check if the sandbox is currently active.
Depot.Test.active()