immutable tri-state
This commit is contained in:
@ -13,6 +13,7 @@ pub struct MockState {
|
||||
pub query_responses: Vec<Result<Value, String>>,
|
||||
pub execute_responses: Vec<Result<(), String>>,
|
||||
pub mocks: Vec<Value>,
|
||||
pub punc_external: bool,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -23,10 +24,12 @@ impl MockState {
|
||||
query_responses: Default::default(),
|
||||
execute_responses: Default::default(),
|
||||
mocks: Default::default(),
|
||||
punc_external: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
thread_local! {
|
||||
pub static MOCK_STATE: RefCell<MockState> = RefCell::new(MockState::new());
|
||||
@ -85,6 +88,10 @@ impl DatabaseExecutor for MockExecutor {
|
||||
Ok("2026-03-10T00:00:00Z".to_string())
|
||||
}
|
||||
|
||||
fn punc_external(&self) -> Result<bool, String> {
|
||||
Ok(MOCK_STATE.with(|state| state.borrow().punc_external))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn get_queries(&self) -> Vec<String> {
|
||||
MOCK_STATE.with(|state| state.borrow().captured_queries.clone())
|
||||
@ -105,10 +112,21 @@ impl DatabaseExecutor for MockExecutor {
|
||||
s.query_responses.clear();
|
||||
s.execute_responses.clear();
|
||||
s.mocks.clear();
|
||||
s.punc_external = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl MockExecutor {
|
||||
pub fn set_punc_external(&self, external: bool) {
|
||||
MOCK_STATE.with(|state| {
|
||||
state.borrow_mut().punc_external = external;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
fn parse_and_match_mocks(sql: &str, mocks: &[Value]) -> Option<Vec<Value>> {
|
||||
let sql_upper = sql.to_uppercase();
|
||||
|
||||
Reference in New Issue
Block a user