|
64 | 64 | SnapshotTableInfo, |
65 | 65 | ) |
66 | 66 | from sqlmesh.utils.date import TimeLike, now, to_date, to_datetime, to_timestamp |
67 | | -from sqlmesh.utils.errors import NoChangesPlanError, SQLMeshError, PlanError |
| 67 | +from sqlmesh.utils.errors import NoChangesPlanError, SQLMeshError, PlanError, ConfigError |
68 | 68 | from sqlmesh.utils.pydantic import validate_string |
69 | 69 | from tests.conftest import DuckDBMetadata, SushiDataValidator |
70 | 70 | from tests.utils.test_helpers import use_terminal_console |
@@ -6129,3 +6129,22 @@ def setup_senario(model_before: str, model_after: str): |
6129 | 6129 | 'Binder Error: Referenced column "this_col_does_not_exist" not found in \nFROM clause!' |
6130 | 6130 | in output.stdout |
6131 | 6131 | ) |
| 6132 | + |
| 6133 | + |
| 6134 | +@pytest.mark.set_default_connection(disable=True) |
| 6135 | +def test_missing_connection_config(): |
| 6136 | + # This is testing the actual implementation of Config.get_connection |
| 6137 | + # To make writing tests easier, it's patched by the autouse fixture provide_sqlmesh_default_connection |
| 6138 | + # Case 1: No default_connection or gateways specified should raise a ConfigError |
| 6139 | + with pytest.raises(ConfigError): |
| 6140 | + ctx = Context(config=Config()) |
| 6141 | + |
| 6142 | + # Case 2: No connection specified in the gateway should raise a ConfigError |
| 6143 | + with pytest.raises(ConfigError): |
| 6144 | + ctx = Context(config=Config(gateways={"incorrect": GatewayConfig()})) |
| 6145 | + |
| 6146 | + # Case 3: Specifying a default_connection or connection in the gateway should work |
| 6147 | + ctx = Context(config=Config(default_connection=DuckDBConnectionConfig())) |
| 6148 | + ctx = Context( |
| 6149 | + config=Config(gateways={"default": GatewayConfig(connection=DuckDBConnectionConfig())}) |
| 6150 | + ) |
0 commit comments