diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index c473d7c64..75a0d3aff 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -202,6 +202,8 @@ def parse_arguments(*arguments): raise ValueError('The --archive option can only be used with the --extract option') if args.restore_paths: raise ValueError('The --restore-path option can only be used with the --extract option') + if args.extract and not args.archive: + raise ValueError('The --archive option is required with the --extract option') if args.progress and not (args.create or args.extract): raise ValueError( diff --git a/tests/integration/commands/test_borgmatic.py b/tests/integration/commands/test_borgmatic.py index d4f11b7bb..f840650ac 100644 --- a/tests/integration/commands/test_borgmatic.py +++ b/tests/integration/commands/test_borgmatic.py @@ -94,6 +94,12 @@ def test_parse_arguments_disallows_encryption_mode_without_init(): module.parse_arguments('--config', 'myconfig', '--encryption', 'repokey') +def test_parse_arguments_allows_encryption_mode_with_init(): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + module.parse_arguments('--config', 'myconfig', '--init', '--encryption', 'repokey') + + def test_parse_arguments_requires_encryption_mode_with_init(): flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) @@ -136,10 +142,48 @@ def test_parse_arguments_disallows_init_and_dry_run(): ) +def test_parse_arguments_disallows_repository_without_extract(): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + with pytest.raises(ValueError): + module.parse_arguments('--config', 'myconfig', '--repository', 'test.borg') + + +def test_parse_arguments_disallows_archive_without_extract(): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + with pytest.raises(ValueError): + module.parse_arguments('--config', 'myconfig', '--archive', 'test') + + +def test_parse_arguments_disallows_restore_paths_without_extract(): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + with pytest.raises(ValueError): + module.parse_arguments('--config', 'myconfig', '--restore-path', 'test') + + +def test_parse_arguments_allows_archive_with_extract(): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + module.parse_arguments('--config', 'myconfig', '--extract', '--archive', 'test') + + +def test_parse_arguments_requires_archive_with_extract(): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + with pytest.raises(ValueError): + module.parse_arguments('--config', 'myconfig', '--extract') + + def test_parse_arguments_allows_progress_and_create(): module.parse_arguments('--progress', '--create', '--list') +def test_parse_arguments_allows_progress_and_extract(): + module.parse_arguments('--progress', '--extract', '--archive', 'test', '--list') + + def test_parse_arguments_disallows_progress_without_create(): with pytest.raises(ValueError): module.parse_arguments('--progress', '--list') diff --git a/tests/unit/commands/test_borgmatic.py b/tests/unit/commands/test_borgmatic.py index 20b74b19c..13fe13aab 100644 --- a/tests/unit/commands/test_borgmatic.py +++ b/tests/unit/commands/test_borgmatic.py @@ -56,7 +56,16 @@ def test_collect_configuration_run_summary_logs_info_for_success(): assert any(log for log in logs if log.levelno == module.logging.INFO) -def test_collect_configuration_run_summary_logs_critical_for_error(): +def test_collect_configuration_run_summary_logs_critical_for_parse_error(): + flexmock(module.validate).should_receive('parse_configuration').and_raise(ValueError) + flexmock(module).should_receive('run_configuration') + + logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=())) + + assert any(log for log in logs if log.levelno == module.logging.CRITICAL) + + +def test_collect_configuration_run_summary_logs_critical_for_run_error(): flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}}) flexmock(module).should_receive('run_configuration').and_raise(ValueError)