From a2c9bb12e5736a77b099ce17a98efac23fc27f79 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Sun, 27 Jul 2025 14:52:30 +0200 Subject: [PATCH] test fixes --- borgmatic/actions/restore.py | 5 ++--- borgmatic/hooks/data_source/utils.py | 6 ++++-- tests/unit/hooks/data_source/test_utils.py | 4 +++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/borgmatic/actions/restore.py b/borgmatic/actions/restore.py index 632c0183..fd6e435c 100644 --- a/borgmatic/actions/restore.py +++ b/borgmatic/actions/restore.py @@ -104,7 +104,7 @@ def get_configured_data_source(config, restore_dump): hook_data_source.get('name'), hook_data_source.get('hostname', 'localhost'), hook_data_source.get('port'), - hook_data_source.get('label'), + hook_data_source.get('label') or hook_data_source.get('container') or UNSPECIFIED, ), restore_dump, default_port, @@ -181,7 +181,7 @@ def restore_single_dump( data_source['name'], data_source.get('hostname'), data_source.get('port'), - data_source.get('label'), + data_source.get('label') or data_source.get('container') or UNSPECIFIED, ), ) @@ -568,7 +568,6 @@ def run_restore( config, restore_dump, ) - # For a dump that wasn't found via an exact match in the configuration, try to fallback # to an "all" data source. if not found_data_source: diff --git a/borgmatic/hooks/data_source/utils.py b/borgmatic/hooks/data_source/utils.py index 6c50472d..194ec1be 100644 --- a/borgmatic/hooks/data_source/utils.py +++ b/borgmatic/hooks/data_source/utils.py @@ -61,7 +61,7 @@ def get_ip_from_container(container): ) except subprocess.CalledProcessError as error: last_error = error - logger.debug(f"Couldn't find container '{container}' with engine '{engine}'") + logger.debug(f"Could not find container '{container}' with engine '{engine}'") continue # Container does not exist network_data = json.loads(output.strip()) @@ -77,4 +77,6 @@ def get_ip_from_container(container): if last_error: raise last_error - return None + raise ValueError( + f"Could not determine ip address for container '{container}'; running in host mode or userspace networking?" + ) diff --git a/tests/unit/hooks/data_source/test_utils.py b/tests/unit/hooks/data_source/test_utils.py index ef7c0b2c..0db4c7ec 100644 --- a/tests/unit/hooks/data_source/test_utils.py +++ b/tests/unit/hooks/data_source/test_utils.py @@ -88,4 +88,6 @@ def test_get_container_ip_container_no_network(): flexmock(utils).should_receive('execute_command_and_capture_output').and_return('{}') - assert utils.get_ip_from_container('yolo') is None + with pytest.raises(ValueError) as exc_info: + utils.get_ip_from_container('yolo') + assert 'Could not determine ip address for container' in str(exc_info.value)