use crate::testing::TestEnv;
use serde::de::DeserializeOwned;
#[allow(dead_code)]
pub fn assert_task_called(env: &TestEnv, task_type: &str, expected_count: usize) {
env.assert_task_called(task_type, expected_count);
}
#[allow(dead_code)] pub fn assert_workflow_completed(env: &TestEnv, workflow_id: &str) {
env.assert_workflow_completed(workflow_id);
}
#[allow(dead_code)] pub fn assert_state_equals<T>(env: &TestEnv, workflow_id: &str, key: &str, expected: &T)
where
T: DeserializeOwned + PartialEq + std::fmt::Debug,
{
env.assert_state_equals(workflow_id, key, expected);
}
#[allow(dead_code)] pub fn assert_workflow_failed(env: &TestEnv, workflow_id: &str) {
use crate::testing::env::ExecutionStatus;
let status = env.workflow_status(workflow_id);
assert!(
matches!(status, Some(ExecutionStatus::Failed(_))),
"Expected workflow '{}' to have failed, but status was {:?}",
workflow_id,
status
);
}
#[allow(dead_code)] pub fn assert_task_called_at_least(env: &TestEnv, task_type: &str, min_count: usize) {
let actual_count = env.task_call_count(task_type);
assert!(
actual_count >= min_count,
"Expected task '{}' to be called at least {} times, but was called {} times",
task_type,
min_count,
actual_count
);
}
#[allow(dead_code)] pub fn assert_task_not_called(env: &TestEnv, task_type: &str) {
assert_task_called(env, task_type, 0);
}
#[allow(dead_code)] pub fn assert_state_exists(env: &TestEnv, workflow_id: &str, key: &str) {
let keys = env.workflow_state_keys(workflow_id);
assert!(
keys.contains(&key.to_string()),
"Expected workflow '{}' to have state key '{}', but it was not found. Available keys: {:?}",
workflow_id,
key,
keys
);
}
#[allow(dead_code)] pub fn assert_tasks_executed_in_order(env: &TestEnv, workflow_id: &str, expected_order: &[&str]) {
let executed = env.executed_tasks(workflow_id);
assert_eq!(
executed.len(),
expected_order.len(),
"Expected {} tasks to be executed, but {} were executed",
expected_order.len(),
executed.len()
);
for (i, expected) in expected_order.iter().enumerate() {
assert_eq!(
executed[i], *expected,
"Expected task at position {} to be '{}', but was '{}'",
i, expected, executed[i]
);
}
}
#[allow(dead_code)] pub fn assert_tasks_executed(env: &TestEnv, workflow_id: &str, expected_tasks: &[&str]) {
let executed = env.executed_tasks(workflow_id);
for expected in expected_tasks {
assert!(
executed.contains(&expected.to_string()),
"Expected task '{}' to be executed, but it was not. Executed tasks: {:?}",
expected,
executed
);
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_assertions_module_compiles() {
}
}