diff --git a/airbyte_cdk/test/standard_tests/_job_runner.py b/airbyte_cdk/test/standard_tests/_job_runner.py index 3bb0ea470..07be77420 100644 --- a/airbyte_cdk/test/standard_tests/_job_runner.py +++ b/airbyte_cdk/test/standard_tests/_job_runner.py @@ -75,7 +75,8 @@ def run_test_job( empty_if_missing=True, connector_root=connector_root, ) - if config_dict and verb != "spec": + has_config = test_scenario.config_dict is not None or test_scenario.config_path is not None + if verb != "spec" and (config_dict or has_config): # Write the config to a temp json file and pass the path to the file as an argument. config_path = ( Path(tempfile.gettempdir()) / "airbyte-test" / f"temp_config_{uuid.uuid4().hex}.json" diff --git a/unit_tests/test/test_job_runner_config.py b/unit_tests/test/test_job_runner_config.py new file mode 100644 index 000000000..93df70655 --- /dev/null +++ b/unit_tests/test/test_job_runner_config.py @@ -0,0 +1,93 @@ +from pathlib import Path +from typing import Any + +import pytest + +from airbyte_cdk.test import entrypoint_wrapper +from airbyte_cdk.test.entrypoint_wrapper import EntrypointOutput +from airbyte_cdk.test.models.scenario import ConnectorTestScenario +from airbyte_cdk.test.standard_tests._job_runner import run_test_job + + +def _run_test_job_args( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, + scenario: ConnectorTestScenario, + verb: str = "discover", +) -> list[str]: + captured_args: list[str] = [] + + def fake_run_command( + *, + source: Any, + args: list[str], + expected_outcome: Any, + ) -> EntrypointOutput: + captured_args.extend(args) + return EntrypointOutput(messages=[], command=args) + + monkeypatch.setattr(entrypoint_wrapper, "_run_command", fake_run_command) + run_test_job( + object, # type: ignore[arg-type] + verb, # type: ignore[arg-type] + connector_root=tmp_path, + test_scenario=scenario, + ) + return captured_args + + +def test_config_path_with_empty_object_passes_config( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, +) -> None: + config_path = tmp_path / "config.json" + config_path.write_text("{}") + + args = _run_test_job_args( + monkeypatch, + tmp_path, + ConnectorTestScenario(config_path=config_path), + ) + + assert "--config" in args + config_index = args.index("--config") + 1 + assert Path(args[config_index]).read_text() == "{}" + + +def test_config_dict_passes_config( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, +) -> None: + args = _run_test_job_args( + monkeypatch, + tmp_path, + ConnectorTestScenario(config_dict={"a": 1}), + ) + + assert "--config" in args + + +def test_missing_config_does_not_pass_config( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, +) -> None: + args = _run_test_job_args(monkeypatch, tmp_path, ConnectorTestScenario()) + + assert "--config" not in args + + +def test_spec_does_not_pass_config( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, +) -> None: + config_path = tmp_path / "config.json" + config_path.write_text("{}") + + args = _run_test_job_args( + monkeypatch, + tmp_path, + ConnectorTestScenario(config_path=config_path), + verb="spec", + ) + + assert "--config" not in args