March Docs

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

fnstart_sandboxstart_sandbox()#

Start the test sandbox. Call once at the beginning of a test suite. Enables checkout/checkin lifecycle for test isolation.

Depot.Test.start_sandbox()

fncheckoutcheckout(tables)#

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"])

fncheckincheckin()#

Roll back all sandboxed tables to their checkout snapshot. Call after each test to undo any writes.

Depot.Test.checkin()

fnstop_sandboxstop_sandbox()#

Stop the sandbox. Call at the end of a test suite.

Depot.Test.stop_sandbox()

fnsandboxedsandboxed(tables, func)#

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 ... )

fnactiveactive()#

Check if the sandbox is currently active.

Depot.Test.active()