queryer merger test progress
This commit is contained in:
64
src/database/executors/mock.rs
Normal file
64
src/database/executors/mock.rs
Normal file
@ -0,0 +1,64 @@
|
||||
use crate::database::executors::DatabaseExecutor;
|
||||
use serde_json::Value;
|
||||
|
||||
#[cfg(test)]
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[cfg(test)]
|
||||
pub struct MockExecutor {
|
||||
pub query_responses: Mutex<Vec<Result<Value, String>>>,
|
||||
pub execute_responses: Mutex<Vec<Result<(), String>>>,
|
||||
pub captured_queries: Mutex<Vec<String>>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl MockExecutor {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
query_responses: Mutex::new(Vec::new()),
|
||||
execute_responses: Mutex::new(Vec::new()),
|
||||
captured_queries: Mutex::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl DatabaseExecutor for MockExecutor {
|
||||
fn query(&self, sql: &str, _args: Option<&[Value]>) -> Result<Value, String> {
|
||||
println!("DEBUG SQL QUERY: {}", sql);
|
||||
self.captured_queries.lock().unwrap().push(sql.to_string());
|
||||
let mut responses = self.query_responses.lock().unwrap();
|
||||
if responses.is_empty() {
|
||||
return Ok(Value::Array(vec![]));
|
||||
}
|
||||
responses.remove(0)
|
||||
}
|
||||
|
||||
fn execute(&self, sql: &str, _args: Option<&[Value]>) -> Result<(), String> {
|
||||
println!("DEBUG SQL EXECUTE: {}", sql);
|
||||
self.captured_queries.lock().unwrap().push(sql.to_string());
|
||||
let mut responses = self.execute_responses.lock().unwrap();
|
||||
if responses.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
responses.remove(0)
|
||||
}
|
||||
|
||||
fn auth_user_id(&self) -> Result<String, String> {
|
||||
Ok("00000000-0000-0000-0000-000000000000".to_string())
|
||||
}
|
||||
|
||||
fn timestamp(&self) -> Result<String, String> {
|
||||
Ok("2026-03-10T00:00:00Z".to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn get_queries(&self) -> Vec<String> {
|
||||
self.captured_queries.lock().unwrap().clone()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn reset_mocks(&self) {
|
||||
self.captured_queries.lock().unwrap().clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user