|
19 | 19 | ClonePolicyErrorTestCase, |
20 | 20 | ClonePythonFunctionE2ETestCase, |
21 | 21 | MissingUpstreamFixesE2ETestCase, |
| 22 | + PartialDeferCloneE2ETestCase, |
| 23 | + UnwritableConsumptionDeferCloneE2ETestCase, |
22 | 24 | ) |
23 | 25 | from tests.e2e.src.sqlbuild.cli.commands.main.clone.helpers import ( |
24 | 26 | MISSING_UPSTREAMS, |
| 27 | + defer_clone_with_missing_origin, |
25 | 28 | plan_missing_upstreams, |
26 | 29 | ) |
27 | 30 | from tests.e2e.src.sqlbuild.cli.commands.shared.helpers import ( |
@@ -1050,6 +1053,13 @@ def test_given_missing_upstreams_when_planning_then_s301_lists_them_with_fixes( |
1050 | 1053 | expected_clone_command="sqb clone --from prod --to dev -s " |
1051 | 1054 | + " ".join(MISSING_UPSTREAMS), |
1052 | 1055 | ), |
| 1056 | + CloneMissingUpstreamE2ETestCase( |
| 1057 | + description="a default target that does not exist still yields a runnable clone", |
| 1058 | + default_target="retired", |
| 1059 | + target_args=("--target", "dev"), |
| 1060 | + expected_clone_command="sqb clone --from prod --to dev -s " |
| 1061 | + + " ".join(MISSING_UPSTREAMS), |
| 1062 | + ), |
1053 | 1063 | ], |
1054 | 1064 | ids=lambda case: case.description, |
1055 | 1065 | ) |
@@ -1077,3 +1087,63 @@ def test_given_missing_upstreams_when_running_printed_clone_then_plan_succeeds( |
1077 | 1087 | assert printed == [test_case.expected_clone_command], refused.stdout + refused.stderr |
1078 | 1088 | assert cloned.returncode == 0, cloned.stdout + cloned.stderr |
1079 | 1089 | assert planned.returncode == 0, planned.stdout + planned.stderr |
| 1090 | + |
| 1091 | + |
| 1092 | +@pytest.mark.parametrize( |
| 1093 | + "test_case", |
| 1094 | + [ |
| 1095 | + PartialDeferCloneE2ETestCase( |
| 1096 | + description="a boundary cloned before another failed still rebuilds", |
| 1097 | + dropped_origin_table="customers", |
| 1098 | + expected_fragments=( |
| 1099 | + "orders no completed record", |
| 1100 | + "Unchanged (1): skipped by --changed", |
| 1101 | + ), |
| 1102 | + ), |
| 1103 | + ], |
| 1104 | + ids=lambda case: case.description, |
| 1105 | +) |
| 1106 | +def test_given_partly_failed_defer_clone_when_planning_changed_then_cloned_boundary_rebuilds( |
| 1107 | + test_case: PartialDeferCloneE2ETestCase, |
| 1108 | + tmp_path: Path, |
| 1109 | +) -> None: |
| 1110 | + cloned, planned = defer_clone_with_missing_origin( |
| 1111 | + tmp_path=tmp_path, dropped_origin_table=test_case.dropped_origin_table |
| 1112 | + ) |
| 1113 | + |
| 1114 | + assert cloned.returncode == 1, cloned.stdout + cloned.stderr |
| 1115 | + assert "error[C411]" in cloned.stdout + cloned.stderr |
| 1116 | + assert planned.returncode == 0, planned.stdout + planned.stderr |
| 1117 | + assert all(fragment in planned.stdout for fragment in test_case.expected_fragments), ( |
| 1118 | + planned.stdout |
| 1119 | + ) |
| 1120 | + |
| 1121 | + |
| 1122 | +@pytest.mark.parametrize( |
| 1123 | + "test_case", |
| 1124 | + [ |
| 1125 | + UnwritableConsumptionDeferCloneE2ETestCase( |
| 1126 | + description="the failed boundary is reported, not the consumption write", |
| 1127 | + dropped_origin_table="customers", |
| 1128 | + before_clone=( |
| 1129 | + "DROP TABLE dev._sqlbuild_consumption", |
| 1130 | + "CREATE TABLE dev._sqlbuild_consumption (unexpected INTEGER)", |
| 1131 | + ), |
| 1132 | + expected_fragments=("error[C411]", "customers: missing in origin environment"), |
| 1133 | + ), |
| 1134 | + ], |
| 1135 | + ids=lambda case: case.description, |
| 1136 | +) |
| 1137 | +def test_given_unwritable_consumption_table_when_defer_clone_partly_fails_then_c411_is_reported( |
| 1138 | + test_case: UnwritableConsumptionDeferCloneE2ETestCase, |
| 1139 | + tmp_path: Path, |
| 1140 | +) -> None: |
| 1141 | + cloned, _ = defer_clone_with_missing_origin( |
| 1142 | + tmp_path=tmp_path, |
| 1143 | + dropped_origin_table=test_case.dropped_origin_table, |
| 1144 | + before_clone=test_case.before_clone, |
| 1145 | + ) |
| 1146 | + |
| 1147 | + output: str = cloned.stdout + cloned.stderr |
| 1148 | + assert cloned.returncode == 1, output |
| 1149 | + assert all(fragment in output for fragment in test_case.expected_fragments), output |
0 commit comments