Struct TestDatabase

Source
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 reference
  • B - The database backend type that implements DatabaseBackend

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>

Source

pub async fn setup<F, Fut, T>(&self, f: F) -> Result<T, Box<dyn Error>>
where F: FnOnce(B::Connection) -> Fut, Fut: Future<Output = 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 type
  • Fut - The future type returned by the setup function
  • T - 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,