|
12 | 12 | DuckDBConnectionConfig, |
13 | 13 | GatewayConfig, |
14 | 14 | ModelDefaultsConfig, |
| 15 | + BigQueryConnectionConfig, |
| 16 | + MotherDuckConnectionConfig, |
15 | 17 | ) |
16 | 18 | from sqlmesh.core.config.connection import DuckDBAttachOptions |
17 | 19 | from sqlmesh.core.config.feature_flag import DbtFeatureFlag, FeatureFlag |
@@ -307,6 +309,73 @@ def test_load_config_from_env_invalid_variable_name(): |
307 | 309 | load_config_from_env() |
308 | 310 |
|
309 | 311 |
|
| 312 | +def test_load_yaml_config_env_var_gateway_override(tmp_path_factory): |
| 313 | + config_path = tmp_path_factory.mktemp("yaml_config") / "config.yaml" |
| 314 | + with open(config_path, "w", encoding="utf-8") as fd: |
| 315 | + fd.write( |
| 316 | + """ |
| 317 | +gateways: |
| 318 | + testing: |
| 319 | + connection: |
| 320 | + type: motherduck |
| 321 | + database: blah |
| 322 | +model_defaults: |
| 323 | + dialect: bigquery |
| 324 | + """ |
| 325 | + ) |
| 326 | + with mock.patch.dict( |
| 327 | + os.environ, |
| 328 | + { |
| 329 | + "SQLMESH__GATEWAYS__TESTING__STATE_CONNECTION__TYPE": "bigquery", |
| 330 | + "SQLMESH__DEFAULT_GATEWAY": "testing", |
| 331 | + }, |
| 332 | + ): |
| 333 | + assert load_config_from_paths( |
| 334 | + Config, |
| 335 | + project_paths=[config_path], |
| 336 | + ) == Config( |
| 337 | + gateways={ |
| 338 | + "testing": GatewayConfig( |
| 339 | + connection=MotherDuckConnectionConfig(database="blah"), |
| 340 | + state_connection=BigQueryConnectionConfig(), |
| 341 | + ), |
| 342 | + }, |
| 343 | + model_defaults=ModelDefaultsConfig(dialect="bigquery"), |
| 344 | + default_gateway="testing", |
| 345 | + ) |
| 346 | + |
| 347 | + |
| 348 | +def test_load_py_config_env_var_gateway_override(tmp_path_factory): |
| 349 | + config_path = tmp_path_factory.mktemp("python_config") / "config.py" |
| 350 | + with open(config_path, "w", encoding="utf-8") as fd: |
| 351 | + fd.write( |
| 352 | + """from sqlmesh.core.config import Config, DuckDBConnectionConfig, GatewayConfig, ModelDefaultsConfig |
| 353 | +config = Config(gateways={"duckdb_gateway": GatewayConfig(connection=DuckDBConnectionConfig())}, model_defaults=ModelDefaultsConfig(dialect='')) |
| 354 | + """ |
| 355 | + ) |
| 356 | + with mock.patch.dict( |
| 357 | + os.environ, |
| 358 | + { |
| 359 | + "SQLMESH__GATEWAYS__DUCKDB_GATEWAY__STATE_CONNECTION__TYPE": "bigquery", |
| 360 | + "SQLMESH__DEFAULT_GATEWAY": "duckdb_gateway", |
| 361 | + }, |
| 362 | + ): |
| 363 | + config = load_config_from_paths( |
| 364 | + Config, |
| 365 | + project_paths=[config_path], |
| 366 | + ) |
| 367 | + assert config == Config( |
| 368 | + gateways={ # type: ignore |
| 369 | + "duckdb_gateway": GatewayConfig( |
| 370 | + connection=DuckDBConnectionConfig(), |
| 371 | + state_connection=BigQueryConnectionConfig(), |
| 372 | + ), |
| 373 | + }, |
| 374 | + model_defaults=ModelDefaultsConfig(dialect=""), |
| 375 | + default_gateway="duckdb_gateway", |
| 376 | + ) |
| 377 | + |
| 378 | + |
310 | 379 | def test_load_config_from_python_module_missing_config(tmp_path): |
311 | 380 | config_path = tmp_path / "missing_config.py" |
312 | 381 | with open(config_path, "w", encoding="utf-8") as fd: |
|
0 commit comments