|
| 1 | +# ruff: noqa: S105, S108 |
| 2 | + |
1 | 3 | import glob |
2 | 4 | import os |
3 | 5 | from pathlib import Path |
@@ -262,3 +264,72 @@ def test_tdm_current_records_most_recent_version(timdex_metadata_with_deltas): |
262 | 264 | == most_recent.iloc[0]["run_timestamp"] |
263 | 265 | ) |
264 | 266 | assert current_version.iloc[0]["run_id"] == most_recent.iloc[0]["run_id"] |
| 267 | + |
| 268 | + |
| 269 | +def test_tdm_prepare_duckdb_secret_and_extensions_home_env_var_set_and_valid( |
| 270 | + monkeypatch, tmp_path_factory, timdex_dataset_with_runs |
| 271 | +): |
| 272 | + preset_home = tmp_path_factory.mktemp("my-account") |
| 273 | + monkeypatch.setenv("HOME", str(preset_home)) |
| 274 | + |
| 275 | + tdm = TIMDEXDatasetMetadata(timdex_dataset_with_runs.location) |
| 276 | + df = ( |
| 277 | + tdm.conn.query( |
| 278 | + """ |
| 279 | + select |
| 280 | + current_setting('secret_directory') as secret_directory, |
| 281 | + current_setting('extension_directory') as extension_directory |
| 282 | + ; |
| 283 | + """ |
| 284 | + ) |
| 285 | + .to_df() |
| 286 | + .iloc[0] |
| 287 | + ) |
| 288 | + assert "my-account" in df.secret_directory |
| 289 | + assert df.extension_directory == "" # expected and okay when HOME set |
| 290 | + |
| 291 | + |
| 292 | +def test_tdm_prepare_duckdb_secret_and_extensions_home_env_var_unset( |
| 293 | + monkeypatch, timdex_dataset_with_runs |
| 294 | +): |
| 295 | + monkeypatch.delenv("HOME", raising=False) |
| 296 | + |
| 297 | + tdm = TIMDEXDatasetMetadata(timdex_dataset_with_runs.location) |
| 298 | + |
| 299 | + df = ( |
| 300 | + tdm.conn.query( |
| 301 | + """ |
| 302 | + select |
| 303 | + current_setting('secret_directory') as secret_directory, |
| 304 | + current_setting('extension_directory') as extension_directory |
| 305 | + ; |
| 306 | + """ |
| 307 | + ) |
| 308 | + .to_df() |
| 309 | + .iloc[0] |
| 310 | + ) |
| 311 | + assert df.secret_directory == "/tmp/.duckdb/secrets" |
| 312 | + assert df.extension_directory == "/tmp/.duckdb/extensions" |
| 313 | + |
| 314 | + |
| 315 | +def test_tdm_prepare_duckdb_secret_and_extensions_home_env_var_set_but_empty( |
| 316 | + monkeypatch, timdex_dataset_with_runs |
| 317 | +): |
| 318 | + monkeypatch.setenv("HOME", "") # simulate AWS Lambda environment |
| 319 | + |
| 320 | + tdm = TIMDEXDatasetMetadata(timdex_dataset_with_runs.location) |
| 321 | + |
| 322 | + df = ( |
| 323 | + tdm.conn.query( |
| 324 | + """ |
| 325 | + select |
| 326 | + current_setting('secret_directory') as secret_directory, |
| 327 | + current_setting('extension_directory') as extension_directory |
| 328 | + ; |
| 329 | + """ |
| 330 | + ) |
| 331 | + .to_df() |
| 332 | + .iloc[0] |
| 333 | + ) |
| 334 | + assert df.secret_directory == "/tmp/.duckdb/secrets" |
| 335 | + assert df.extension_directory == "/tmp/.duckdb/extensions" |
0 commit comments