pub struct MockDatabaseBackend { /* private fields */ }Expand description
Mock implementation of DatabaseBackend trait using mockall
This mock provides automatic verification of method calls and arguments.
§Usage with rstest Fixtures
For complete examples using rstest fixtures, see the unit tests in this module:
test_mock_execute_with_verification()- Demonstrates strict argument verificationtest_with_mock_database()- Shows usage with themock_databasefixturetest_with_mock_connection()- Shows usage with themock_connectionfixture
§Direct Usage Example
use reinhardt_testkit::fixtures::MockDatabaseBackend;
use reinhardt_db::backends::types::{QueryResult, QueryValue};
use reinhardt_db::backends::backend::DatabaseBackend as BackendTrait;
#[tokio::main]
async fn main() {
let mut mock = MockDatabaseBackend::new();
// Set expectations with strict argument verification
mock.expect_execute()
.withf(|sql, params| {
sql.contains("INSERT INTO users") && params.len() == 2
})
.times(1)
.returning(|_, _| Ok(QueryResult { rows_affected: 1 }));
// Execute the query (must call to satisfy .times(1) expectation)
let result = mock.execute(
"INSERT INTO users (name, email) VALUES ($1, $2)",
vec![
QueryValue::String("Alice".to_string()),
QueryValue::String("alice@example.com".to_string()),
],
).await;
assert!(result.is_ok());
// Mock automatically verifies expectations on drop
}Implementations§
Source§impl MockDatabaseBackend
impl MockDatabaseBackend
Sourcepub fn checkpoint(&mut self)
pub fn checkpoint(&mut self)
Validate that all current expectations for all methods have been satisfied, and discard them.
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new mock object with no expectations.
This method will not be generated if the real struct
already has a new method. However, it will be
generated if the struct implements a trait with a new
method. The trait’s new method can still be called
like <MockX as TraitY>::new
Source§impl MockDatabaseBackend
impl MockDatabaseBackend
Sourcepub fn expect_database_type(&mut self) -> &mut Expectation
pub fn expect_database_type(&mut self) -> &mut Expectation
Create an Expectation for mocking the database_type method
Sourcepub fn expect_placeholder(&mut self) -> &mut Expectation
pub fn expect_placeholder(&mut self) -> &mut Expectation
Create an Expectation for mocking the placeholder method
Sourcepub fn expect_supports_returning(&mut self) -> &mut Expectation
pub fn expect_supports_returning(&mut self) -> &mut Expectation
Create an Expectation for mocking the supports_returning method
Sourcepub fn expect_supports_on_conflict(&mut self) -> &mut Expectation
pub fn expect_supports_on_conflict(&mut self) -> &mut Expectation
Create an Expectation for mocking the supports_on_conflict method
Sourcepub fn expect_execute(&mut self) -> &mut Expectation
pub fn expect_execute(&mut self) -> &mut Expectation
Create an Expectation for mocking the execute method
Sourcepub fn expect_fetch_one(&mut self) -> &mut Expectation
pub fn expect_fetch_one(&mut self) -> &mut Expectation
Create an Expectation for mocking the fetch_one method
Sourcepub fn expect_fetch_all(&mut self) -> &mut Expectation
pub fn expect_fetch_all(&mut self) -> &mut Expectation
Create an Expectation for mocking the fetch_all method
Sourcepub fn expect_fetch_optional(&mut self) -> &mut Expectation
pub fn expect_fetch_optional(&mut self) -> &mut Expectation
Create an Expectation for mocking the fetch_optional method
Sourcepub fn expect_begin(&mut self) -> &mut Expectation
pub fn expect_begin(&mut self) -> &mut Expectation
Create an Expectation for mocking the begin method
Sourcepub fn expect_as_any(&mut self) -> &mut Expectation
pub fn expect_as_any(&mut self) -> &mut Expectation
Create an Expectation for mocking the as_any method
Trait Implementations§
Source§impl DatabaseBackend for MockDatabaseBackend
impl DatabaseBackend for MockDatabaseBackend
Source§fn database_type(&self) -> DatabaseType
fn database_type(&self) -> DatabaseType
Source§fn placeholder(&self, index: usize) -> String
fn placeholder(&self, index: usize) -> String
Source§fn supports_returning(&self) -> bool
fn supports_returning(&self) -> bool
Source§fn supports_on_conflict(&self) -> bool
fn supports_on_conflict(&self) -> bool
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<QueryResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<QueryResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn fetch_one<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Row>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn fetch_one<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Row>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn fetch_all<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn fetch_all<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn fetch_optional<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Option<Row>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn fetch_optional<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Option<Row>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn begin<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn TransactionExecutor>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn begin<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn TransactionExecutor>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn supports_transactional_ddl(&self) -> bool
fn supports_transactional_ddl(&self) -> bool
Source§fn begin_with_isolation<'life0, 'async_trait>(
&'life0 self,
isolation_level: IsolationLevel,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn TransactionExecutor>, DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn begin_with_isolation<'life0, 'async_trait>(
&'life0 self,
isolation_level: IsolationLevel,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn TransactionExecutor>, DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Source§impl Default for MockDatabaseBackend
impl Default for MockDatabaseBackend
impl Send for MockDatabaseBackend
impl Sync for MockDatabaseBackend
Auto Trait Implementations§
impl Freeze for MockDatabaseBackend
impl !RefUnwindSafe for MockDatabaseBackend
impl Unpin for MockDatabaseBackend
impl UnsafeUnpin for MockDatabaseBackend
impl !UnwindSafe for MockDatabaseBackend
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
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().