pub struct TestDatabase<'a, B: DatabaseBackend> {
pub test_pool: &'a B::Pool,
pub test_user: String,
}
Expand description
A test database instance that provides access to a connection pool and test-specific data.
This struct is generic over the database backend type and provides methods for setting up and interacting with a test database instance.
§Type Parameters
'a
- The lifetime of the database pool referenceB
- The database backend type that implementsDatabaseBackend
Fields§
§test_pool: &'a B::Pool
The connection pool for this test database
test_user: String
A unique identifier for the test user, useful for test data isolation
Implementations§
Source§impl<'a, B: DatabaseBackend> TestDatabase<'a, B>
impl<'a, B: DatabaseBackend> TestDatabase<'a, B>
Sourcepub async fn setup<F, Fut, T>(&self, f: F) -> Result<T, Box<dyn Error>>
pub async fn setup<F, Fut, T>(&self, f: F) -> Result<T, Box<dyn Error>>
Sets up the test database by executing the provided setup function.
This method acquires a connection from the pool, executes the setup function with that connection, and returns the result.
§Type Parameters
F
- The setup function typeFut
- The future type returned by the setup functionT
- The result type of the setup function
§Arguments
f
- A function that takes a database connection and returns a future
§Returns
Returns a Result
containing the value returned by the setup function, or an error
if the setup failed.
Auto Trait Implementations§
impl<'a, B> Freeze for TestDatabase<'a, B>
impl<'a, B> RefUnwindSafe for TestDatabase<'a, B>
impl<'a, B> Send for TestDatabase<'a, B>
impl<'a, B> Sync for TestDatabase<'a, B>
impl<'a, B> Unpin for TestDatabase<'a, B>
impl<'a, B> UnwindSafe for TestDatabase<'a, B>
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