Skip to main content

stormchaser_engine/db/steps/
tests.rs

1use sqlx::{Executor, Postgres};
2use stormchaser_model::test_report;
3use uuid::Uuid;
4
5/// Get test summaries for run.
6pub async fn get_test_summaries_for_run<'a, E>(
7    executor: E,
8    run_id: Uuid,
9) -> Result<Vec<test_report::TestSummary>, sqlx::Error>
10where
11    E: Executor<'a, Database = Postgres>,
12{
13    sqlx::query_as(
14        r#"
15        WITH combined AS (
16            SELECT * FROM step_test_summaries
17            UNION ALL
18            SELECT * FROM archived_step_test_summaries
19        )
20        SELECT * FROM combined WHERE run_id = $1 ORDER BY created_at ASC
21        "#,
22    )
23    .bind(run_id)
24    .fetch_all(executor)
25    .await
26}
27
28/// Get test cases for report.
29pub async fn get_test_cases_for_report<'a, E>(
30    executor: E,
31    run_id: Uuid,
32    report_name: &str,
33) -> Result<Vec<test_report::TestCase>, sqlx::Error>
34where
35    E: Executor<'a, Database = Postgres>,
36{
37    sqlx::query_as(
38        r#"
39        WITH combined AS (
40            SELECT id, run_id, step_instance_id, report_name, test_suite, test_case, status::text as status, duration_ms, message, created_at FROM step_test_cases
41            UNION ALL
42            SELECT id, run_id, step_instance_id, report_name, test_suite, test_case, status::text as status, duration_ms, message, created_at FROM archived_step_test_cases
43        )
44        SELECT id, run_id, step_instance_id, report_name, test_suite, test_case, status::test_case_status as status, duration_ms, message, created_at
45        FROM combined WHERE run_id = $1 AND report_name = $2 ORDER BY created_at ASC
46        "#,
47    )
48    .bind(run_id)
49    .bind(report_name)
50    .fetch_all(executor)
51    .await
52}