Skip to content

Commit

Permalink
make connector_configuration_path optional in ContainerRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
alafanechere committed Dec 2, 2022
1 parent 7a8ecde commit 234ba61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


class ConnectorRunner:
def __init__(self, image_name: str, volume: Path, connector_configuration_path: Optional[Path], should_persist_new_configurations=True):
def __init__(self, image_name: str, volume: Path, connector_configuration_path: Optional[Path] = None):
self._client = docker.from_env()
try:
self._image = self._client.images.get(image_name)
Expand All @@ -28,7 +28,6 @@ def __init__(self, image_name: str, volume: Path, connector_configuration_path:
self._runs = 0
self._volume_base = volume
self._connector_configuration_path = connector_configuration_path
self._should_persist_new_configurations = should_persist_new_configurations

@property
def output_folder(self) -> Path:
Expand Down Expand Up @@ -182,8 +181,8 @@ def entry_point(self):
return self._image.attrs["Config"]["Entrypoint"]

def _persist_new_configuration(self, new_configuration: dict, configuration_emitted_at: int) -> Optional[Path]:
if not self._should_persist_new_configurations:
logging.warning("New configuration persistence is disabled. The new configuration was not persisted")
if self._connector_configuration_path is None:
logging.warning("No configuration path was passed to the ConnectorRunner. The new configuration was not persisted")
return None

with open(self._connector_configuration_path) as old_configuration_file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def test_run_call_persist_configuration(self, mocker, tmp_path):
mocker.patch.object(connector_runner.ConnectorRunner, "read", mocker.Mock(return_value=records_reads))
mocker.patch.object(connector_runner.ConnectorRunner, "_persist_new_configuration")

runner = connector_runner.ConnectorRunner("source-test:dev", tmp_path, old_configuration_path)
runner = connector_runner.ConnectorRunner("source-test:dev", tmp_path, connector_configuration_path=old_configuration_path)
list(runner.run("dummy_cmd"))
runner._persist_new_configuration.assert_called_once_with(new_configuration, 1)

@pytest.mark.parametrize(
"should_persist_new_configurations, old_configuration, new_configuration, new_configuration_emitted_at, expect_new_configuration",
"pass_configuration_path, old_configuration, new_configuration, new_configuration_emitted_at, expect_new_configuration",
[
pytest.param(
True,
Expand All @@ -70,17 +70,20 @@ def test_persist_new_configuration(
self,
mocker,
tmp_path,
should_persist_new_configurations,
pass_configuration_path,
old_configuration,
new_configuration,
new_configuration_emitted_at,
expect_new_configuration,
):
old_configuration_path = tmp_path / "config.json"
with open(old_configuration_path, "w") as old_configuration_file:
json.dump(old_configuration, old_configuration_file)
if pass_configuration_path:
old_configuration_path = tmp_path / "config.json"
with open(old_configuration_path, "w") as old_configuration_file:
json.dump(old_configuration, old_configuration_file)
else:
old_configuration_path = None
mocker.patch.object(connector_runner, "docker")
runner = connector_runner.ConnectorRunner("source-test:dev", tmp_path, old_configuration_path, should_persist_new_configurations)
runner = connector_runner.ConnectorRunner("source-test:dev", tmp_path, old_configuration_path)
new_configuration_path = runner._persist_new_configuration(new_configuration, new_configuration_emitted_at)
if not expect_new_configuration:
assert new_configuration_path is None
Expand Down

0 comments on commit 234ba61

Please sign in to comment.