|
| 1 | +use crate::test_targets::main::scenario_source_violation::scenario_source_violation; |
| 2 | +use crate::test_targets::tests::helpers::cte; |
| 3 | +use crate::test_targets::tests::test_types::ScenarioSourceTestCase; |
| 4 | + |
| 5 | +#[test] |
| 6 | +fn given_scenario_sources_when_validating_then_python_first_error_is_returned() { |
| 7 | + let test_cases = [ |
| 8 | + ScenarioSourceTestCase { |
| 9 | + description: "known sources in fixtures pass", |
| 10 | + ctes: vec![ |
| 11 | + cte("__source__raw", false, &["raw"]), |
| 12 | + cte("__expected__orders", true, &[]), |
| 13 | + ], |
| 14 | + expected_error: None, |
| 15 | + }, |
| 16 | + ScenarioSourceTestCase { |
| 17 | + description: "a check CTE reading a source is reported before unknown fixture sources", |
| 18 | + ctes: vec![ |
| 19 | + cte("helper", false, &["missing"]), |
| 20 | + cte("__expected__orders", true, &["raw"]), |
| 21 | + ], |
| 22 | + expected_error: Some( |
| 23 | + "SQL scenario file tests/scenarios/orders.sql CTE '__expected__orders' must not reference project source 'raw' with __source(); source-backed scenario data is only allowed in helper and fixture CTEs", |
| 24 | + ), |
| 25 | + }, |
| 26 | + ScenarioSourceTestCase { |
| 27 | + description: "an unknown source in a helper CTE", |
| 28 | + ctes: vec![cte("helper", false, &["raw", "missing"])], |
| 29 | + expected_error: Some( |
| 30 | + "SQL scenario file tests/scenarios/orders.sql references unknown source 'missing'", |
| 31 | + ), |
| 32 | + }, |
| 33 | + ]; |
| 34 | + |
| 35 | + for test_case in test_cases { |
| 36 | + assert_eq!( |
| 37 | + scenario_source_violation( |
| 38 | + "tests/scenarios/orders.sql", |
| 39 | + &test_case.ctes, |
| 40 | + &["raw".to_owned()] |
| 41 | + ) |
| 42 | + .as_deref(), |
| 43 | + test_case.expected_error, |
| 44 | + "{}", |
| 45 | + test_case.description |
| 46 | + ); |
| 47 | + } |
| 48 | +} |
0 commit comments