diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 31f18e1..d346662 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -403,7 +403,8 @@ def collect_configuration_run_summary_logs(config_filenames, args): ) yield logging.makeLogRecord(dict(levelno=logging.CRITICAL, msg=error)) - validate.guard_configuration_contains_repository(args.repository, configs) + if args.extract: + validate.guard_configuration_contains_repository(args.repository, configs) for config_filename, config in configs.items(): try: diff --git a/tests/unit/commands/test_borgmatic.py b/tests/unit/commands/test_borgmatic.py index 278b6be..59d879f 100644 --- a/tests/unit/commands/test_borgmatic.py +++ b/tests/unit/commands/test_borgmatic.py @@ -48,10 +48,20 @@ def test_run_commands_handles_multiple_json_outputs_in_array(): def test_collect_configuration_run_summary_logs_info_for_success(): + flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}}) + flexmock(module).should_receive('run_configuration') + args = flexmock(extract=False) + + logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args)) + + assert any(log for log in logs if log.levelno == module.logging.INFO) + + +def test_collect_configuration_run_summary_still_succeeds_when_extract_true(): flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}}) flexmock(module.validate).should_receive('guard_configuration_contains_repository') flexmock(module).should_receive('run_configuration') - args = flexmock(repository=None) + args = flexmock(extract=True, repository='repo') logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args)) @@ -60,8 +70,7 @@ def test_collect_configuration_run_summary_logs_info_for_success(): def test_collect_configuration_run_summary_logs_critical_for_parse_error(): flexmock(module.validate).should_receive('parse_configuration').and_raise(ValueError) - flexmock(module.validate).should_receive('guard_configuration_contains_repository') - args = flexmock(repository=None) + args = flexmock(extract=False) logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args)) @@ -72,7 +81,7 @@ def test_collect_configuration_run_summary_logs_critical_for_run_error(): flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}}) flexmock(module.validate).should_receive('guard_configuration_contains_repository') flexmock(module).should_receive('run_configuration').and_raise(ValueError) - args = flexmock(repository=None) + args = flexmock(extract=False) logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args)) @@ -81,9 +90,8 @@ def test_collect_configuration_run_summary_logs_critical_for_run_error(): def test_collect_configuration_run_summary_logs_critical_for_missing_configs(): flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}}) - flexmock(module.validate).should_receive('guard_configuration_contains_repository') flexmock(module).should_receive('run_configuration') - args = flexmock(config_paths=(), repository=None) + args = flexmock(config_paths=(), extract=False) logs = tuple(module.collect_configuration_run_summary_logs(config_filenames=(), args=args))