pub struct TestDb { /* private fields */ }Expand description
A database created for one test and dropped when the test is done.
Implementations§
Source§impl TestDb
impl TestDb
Sourcepub async fn create(admin: &PgBackend) -> Result<TestDb, RelError>
pub async fn create(admin: &PgBackend) -> Result<TestDb, RelError>
Create an empty database on the server admin is connected to and connect to it (a pool of up
to 8 connections, the admin connection’s options otherwise).
Sourcepub fn backend(&self) -> &PgBackend
pub fn backend(&self) -> &PgBackend
The backend on the test database. Its pool is the sqlx pool for
sqlx::query! and anything this layer does not carry.
Sourcepub async fn migrate(
&self,
migrations: &[Migration],
) -> Result<MigrateReport, MigrateError>
pub async fn migrate( &self, migrations: &[Migration], ) -> Result<MigrateReport, MigrateError>
Apply migrations to the test database (see PgBackend::migrate).
Sourcepub async fn drop_database(self) -> Result<(), RelError>
pub async fn drop_database(self) -> Result<(), RelError>
Drop the database now, and report whether that worked. The server ends every connection to it
(WITH (FORCE)), including one the test still holds: the pool is not asked to close first,
because closing waits for every checked-out connection to come back.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for TestDb
impl !UnwindSafe for TestDb
impl Forget for TestDb
impl Freeze for TestDb
impl Send for TestDb
impl Sync for TestDb
impl Unpin for TestDb
impl UnsafeUnpin for TestDb
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more