2019-06-23 06:32:27 +02:00
|
|
|
import pytest
|
|
|
|
from flexmock import flexmock
|
|
|
|
|
|
|
|
from borgmatic.commands import arguments as module
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_no_arguments_uses_defaults():
|
|
|
|
config_paths = ['default']
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
|
|
|
|
|
|
|
|
arguments = module.parse_arguments()
|
|
|
|
|
|
|
|
global_arguments = arguments['global']
|
|
|
|
assert global_arguments.config_paths == config_paths
|
|
|
|
assert global_arguments.verbosity == 0
|
2023-09-29 23:16:47 +02:00
|
|
|
assert global_arguments.syslog_verbosity == -2
|
|
|
|
assert global_arguments.log_file_verbosity == 1
|
|
|
|
assert global_arguments.monitoring_verbosity == 1
|
2019-06-23 06:32:27 +02:00
|
|
|
|
|
|
|
|
2023-07-14 04:25:14 +02:00
|
|
|
def test_parse_arguments_with_multiple_config_flags_parses_as_list():
|
2019-06-23 06:32:27 +02:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2023-07-14 04:25:14 +02:00
|
|
|
arguments = module.parse_arguments('--config', 'myconfig', '--config', 'otherconfig')
|
2019-06-23 06:32:27 +02:00
|
|
|
|
|
|
|
global_arguments = arguments['global']
|
|
|
|
assert global_arguments.config_paths == ['myconfig', 'otherconfig']
|
|
|
|
assert global_arguments.verbosity == 0
|
2023-09-29 23:16:47 +02:00
|
|
|
assert global_arguments.syslog_verbosity == -2
|
|
|
|
assert global_arguments.log_file_verbosity == 1
|
|
|
|
assert global_arguments.monitoring_verbosity == 1
|
2019-06-23 06:32:27 +02:00
|
|
|
|
|
|
|
|
2023-06-24 23:10:47 +02:00
|
|
|
def test_parse_arguments_with_action_after_config_path_omits_action():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
arguments = module.parse_arguments('--config', 'myconfig', 'list', '--json')
|
|
|
|
|
|
|
|
global_arguments = arguments['global']
|
|
|
|
assert global_arguments.config_paths == ['myconfig']
|
|
|
|
assert 'list' in arguments
|
|
|
|
assert arguments['list'].json
|
|
|
|
|
|
|
|
|
2023-06-25 00:35:10 +02:00
|
|
|
def test_parse_arguments_with_action_after_config_path_omits_aliased_action():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
arguments = module.parse_arguments('--config', 'myconfig', 'init', '--encryption', 'repokey')
|
|
|
|
|
|
|
|
global_arguments = arguments['global']
|
|
|
|
assert global_arguments.config_paths == ['myconfig']
|
|
|
|
assert 'rcreate' in arguments
|
|
|
|
assert arguments['rcreate'].encryption_mode == 'repokey'
|
|
|
|
|
|
|
|
|
2023-06-26 18:30:46 +02:00
|
|
|
def test_parse_arguments_with_action_and_positional_arguments_after_config_path_omits_action_and_arguments():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
arguments = module.parse_arguments('--config', 'myconfig', 'borg', 'key', 'export')
|
|
|
|
|
|
|
|
global_arguments = arguments['global']
|
|
|
|
assert global_arguments.config_paths == ['myconfig']
|
|
|
|
assert 'borg' in arguments
|
|
|
|
assert arguments['borg'].options == ['key', 'export']
|
|
|
|
|
|
|
|
|
2019-06-23 06:32:27 +02:00
|
|
|
def test_parse_arguments_with_verbosity_overrides_default():
|
|
|
|
config_paths = ['default']
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
|
|
|
|
|
|
|
|
arguments = module.parse_arguments('--verbosity', '1')
|
|
|
|
|
|
|
|
global_arguments = arguments['global']
|
|
|
|
assert global_arguments.config_paths == config_paths
|
|
|
|
assert global_arguments.verbosity == 1
|
2023-09-29 23:16:47 +02:00
|
|
|
assert global_arguments.syslog_verbosity == -2
|
|
|
|
assert global_arguments.log_file_verbosity == 1
|
|
|
|
assert global_arguments.monitoring_verbosity == 1
|
2019-06-23 06:32:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_syslog_verbosity_overrides_default():
|
|
|
|
config_paths = ['default']
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
|
|
|
|
|
|
|
|
arguments = module.parse_arguments('--syslog-verbosity', '2')
|
|
|
|
|
|
|
|
global_arguments = arguments['global']
|
|
|
|
assert global_arguments.config_paths == config_paths
|
|
|
|
assert global_arguments.verbosity == 0
|
|
|
|
assert global_arguments.syslog_verbosity == 2
|
2023-09-29 23:16:47 +02:00
|
|
|
assert global_arguments.log_file_verbosity == 1
|
|
|
|
assert global_arguments.monitoring_verbosity == 1
|
2019-06-23 06:32:27 +02:00
|
|
|
|
|
|
|
|
2019-11-03 09:55:19 +01:00
|
|
|
def test_parse_arguments_with_log_file_verbosity_overrides_default():
|
|
|
|
config_paths = ['default']
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
|
|
|
|
|
|
|
|
arguments = module.parse_arguments('--log-file-verbosity', '-1')
|
|
|
|
|
|
|
|
global_arguments = arguments['global']
|
|
|
|
assert global_arguments.config_paths == config_paths
|
|
|
|
assert global_arguments.verbosity == 0
|
2023-09-29 23:16:47 +02:00
|
|
|
assert global_arguments.syslog_verbosity == -2
|
2019-11-03 09:55:19 +01:00
|
|
|
assert global_arguments.log_file_verbosity == -1
|
2023-09-29 23:16:47 +02:00
|
|
|
assert global_arguments.monitoring_verbosity == 1
|
2019-11-03 09:55:19 +01:00
|
|
|
|
|
|
|
|
2020-10-24 01:06:00 +02:00
|
|
|
def test_parse_arguments_with_single_override_parses():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
arguments = module.parse_arguments('--override', 'foo.bar=baz')
|
|
|
|
|
|
|
|
global_arguments = arguments['global']
|
|
|
|
assert global_arguments.overrides == ['foo.bar=baz']
|
|
|
|
|
|
|
|
|
2023-07-14 04:25:14 +02:00
|
|
|
def test_parse_arguments_with_multiple_overrides_flags_parses():
|
2020-10-24 01:06:00 +02:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
arguments = module.parse_arguments(
|
2023-07-14 04:25:14 +02:00
|
|
|
'--override', 'foo.bar=baz', '--override', 'foo.quux=7', '--override', 'this.that=8'
|
2020-10-24 01:06:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
global_arguments = arguments['global']
|
|
|
|
assert global_arguments.overrides == ['foo.bar=baz', 'foo.quux=7', 'this.that=8']
|
|
|
|
|
|
|
|
|
2019-06-23 06:32:27 +02:00
|
|
|
def test_parse_arguments_with_list_json_overrides_default():
|
|
|
|
arguments = module.parse_arguments('list', '--json')
|
|
|
|
|
|
|
|
assert 'list' in arguments
|
|
|
|
assert arguments['list'].json is True
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_no_actions_defaults_to_all_actions_enabled():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
arguments = module.parse_arguments()
|
|
|
|
|
|
|
|
assert 'prune' in arguments
|
|
|
|
assert 'create' in arguments
|
|
|
|
assert 'check' in arguments
|
|
|
|
|
|
|
|
|
2019-09-22 20:30:58 +02:00
|
|
|
def test_parse_arguments_with_no_actions_passes_argument_to_relevant_actions():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2022-08-21 23:25:16 +02:00
|
|
|
arguments = module.parse_arguments('--stats', '--list')
|
2019-09-22 20:30:58 +02:00
|
|
|
|
|
|
|
assert 'prune' in arguments
|
|
|
|
assert arguments['prune'].stats
|
2022-08-21 23:25:16 +02:00
|
|
|
assert arguments['prune'].list_archives
|
2019-09-22 20:30:58 +02:00
|
|
|
assert 'create' in arguments
|
|
|
|
assert arguments['create'].stats
|
2022-08-21 23:25:16 +02:00
|
|
|
assert arguments['create'].list_files
|
2019-09-22 20:30:58 +02:00
|
|
|
assert 'check' in arguments
|
|
|
|
|
|
|
|
|
2019-06-23 06:32:27 +02:00
|
|
|
def test_parse_arguments_with_help_and_no_actions_shows_global_help(capsys):
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit) as exit:
|
|
|
|
module.parse_arguments('--help')
|
|
|
|
|
|
|
|
assert exit.value.code == 0
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert 'global arguments:' in captured.out
|
|
|
|
assert 'actions:' in captured.out
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_help_and_action_shows_action_help(capsys):
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit) as exit:
|
|
|
|
module.parse_arguments('create', '--help')
|
|
|
|
|
|
|
|
assert exit.value.code == 0
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert 'global arguments:' not in captured.out
|
|
|
|
assert 'actions:' not in captured.out
|
|
|
|
assert 'create arguments:' in captured.out
|
|
|
|
|
|
|
|
|
2021-06-18 05:41:44 +02:00
|
|
|
def test_parse_arguments_with_action_before_global_options_parses_options():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
arguments = module.parse_arguments('prune', '--verbosity', '2')
|
|
|
|
|
|
|
|
assert 'prune' in arguments
|
|
|
|
assert arguments['global'].verbosity == 2
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_global_options_before_action_parses_options():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
arguments = module.parse_arguments('--verbosity', '2', 'prune')
|
|
|
|
|
|
|
|
assert 'prune' in arguments
|
|
|
|
assert arguments['global'].verbosity == 2
|
|
|
|
|
|
|
|
|
2019-06-23 06:32:27 +02:00
|
|
|
def test_parse_arguments_with_prune_action_leaves_other_actions_disabled():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
arguments = module.parse_arguments('prune')
|
|
|
|
|
|
|
|
assert 'prune' in arguments
|
|
|
|
assert 'create' not in arguments
|
|
|
|
assert 'check' not in arguments
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_multiple_actions_leaves_other_action_disabled():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
arguments = module.parse_arguments('create', 'check')
|
|
|
|
|
|
|
|
assert 'prune' not in arguments
|
|
|
|
assert 'create' in arguments
|
|
|
|
assert 'check' in arguments
|
|
|
|
|
|
|
|
|
2023-06-24 23:10:47 +02:00
|
|
|
def test_parse_arguments_disallows_invalid_argument():
|
2019-06-23 06:32:27 +02:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2023-06-24 23:10:47 +02:00
|
|
|
with pytest.raises(ValueError):
|
2019-06-23 06:32:27 +02:00
|
|
|
module.parse_arguments('--posix-me-harder')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_disallows_encryption_mode_without_init():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2023-06-24 23:10:47 +02:00
|
|
|
with pytest.raises(ValueError):
|
2019-06-23 06:32:27 +02:00
|
|
|
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'])
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
module.parse_arguments('--config', 'myconfig', 'init')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_disallows_append_only_without_init():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2023-06-24 23:10:47 +02:00
|
|
|
with pytest.raises(ValueError):
|
2019-06-23 06:32:27 +02:00
|
|
|
module.parse_arguments('--config', 'myconfig', '--append-only')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_disallows_storage_quota_without_init():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2023-06-24 23:10:47 +02:00
|
|
|
with pytest.raises(ValueError):
|
2019-06-23 06:32:27 +02:00
|
|
|
module.parse_arguments('--config', 'myconfig', '--storage-quota', '5G')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_allows_init_and_prune():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('--config', 'myconfig', 'init', '--encryption', 'repokey', 'prune')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_allows_init_and_create():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('--config', 'myconfig', 'init', '--encryption', 'repokey', 'create')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_allows_repository_with_extract():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments(
|
|
|
|
'--config', 'myconfig', 'extract', '--repository', 'test.borg', '--archive', 'test'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-11-25 23:56:20 +01:00
|
|
|
def test_parse_arguments_allows_repository_with_mount():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments(
|
|
|
|
'--config',
|
|
|
|
'myconfig',
|
|
|
|
'mount',
|
|
|
|
'--repository',
|
|
|
|
'test.borg',
|
|
|
|
'--archive',
|
|
|
|
'test',
|
|
|
|
'--mount-point',
|
|
|
|
'/mnt',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-06-23 06:32:27 +02:00
|
|
|
def test_parse_arguments_allows_repository_with_list():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('--config', 'myconfig', 'list', '--repository', 'test.borg')
|
|
|
|
|
|
|
|
|
2019-11-25 23:56:20 +01:00
|
|
|
def test_parse_arguments_disallows_archive_unless_action_consumes_it():
|
2019-06-23 06:32:27 +02:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2023-06-24 23:10:47 +02:00
|
|
|
with pytest.raises(ValueError):
|
2019-06-23 06:32:27 +02:00
|
|
|
module.parse_arguments('--config', 'myconfig', '--archive', 'test')
|
|
|
|
|
|
|
|
|
2019-11-25 23:56:20 +01:00
|
|
|
def test_parse_arguments_disallows_paths_unless_action_consumes_it():
|
2019-06-23 06:32:27 +02:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2023-06-24 23:10:47 +02:00
|
|
|
with pytest.raises(ValueError):
|
2019-11-01 18:00:26 +01:00
|
|
|
module.parse_arguments('--config', 'myconfig', '--path', 'test')
|
2019-06-23 06:32:27 +02:00
|
|
|
|
2023-06-06 22:13:01 +02:00
|
|
|
|
2023-06-06 21:26:19 +02:00
|
|
|
def test_parse_arguments_disallows_other_actions_with_config_bootstrap():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments('config', 'bootstrap', '--repository', 'test.borg', 'list')
|
|
|
|
|
2019-06-23 06:32:27 +02:00
|
|
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
|
2019-11-25 23:56:20 +01:00
|
|
|
def test_parse_arguments_allows_archive_with_mount():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments(
|
|
|
|
'--config', 'myconfig', 'mount', '--archive', 'test', '--mount-point', '/mnt'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-10-31 20:57:36 +01:00
|
|
|
def test_parse_arguments_allows_archive_with_restore():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('--config', 'myconfig', 'restore', '--archive', 'test')
|
|
|
|
|
|
|
|
|
2019-06-23 06:32:27 +02:00
|
|
|
def test_parse_arguments_allows_archive_with_list():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('--config', 'myconfig', 'list', '--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(SystemExit):
|
|
|
|
module.parse_arguments('--config', 'myconfig', 'extract')
|
|
|
|
|
|
|
|
|
2019-10-31 20:57:36 +01:00
|
|
|
def test_parse_arguments_requires_archive_with_restore():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
module.parse_arguments('--config', 'myconfig', 'restore')
|
|
|
|
|
|
|
|
|
2019-11-25 23:56:20 +01:00
|
|
|
def test_parse_arguments_requires_mount_point_with_mount():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
module.parse_arguments('--config', 'myconfig', 'mount', '--archive', 'test')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_requires_mount_point_with_umount():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
module.parse_arguments('--config', 'myconfig', 'umount')
|
|
|
|
|
|
|
|
|
2019-06-23 06:32:27 +02:00
|
|
|
def test_parse_arguments_allows_progress_before_create():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('--progress', 'create', 'list')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_allows_progress_after_create():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('create', '--progress', 'list')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_allows_progress_and_extract():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('--progress', 'extract', '--archive', 'test', 'list')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_disallows_progress_without_create():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2023-06-24 23:10:47 +02:00
|
|
|
with pytest.raises(ValueError):
|
2019-06-23 06:32:27 +02:00
|
|
|
module.parse_arguments('--progress', 'list')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_stats_and_create_flags_does_not_raise():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('--stats', 'create', 'list')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_stats_and_prune_flags_does_not_raise():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('--stats', 'prune', 'list')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_stats_flag_but_no_create_or_prune_flag_raises_value_error():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2023-06-24 23:10:47 +02:00
|
|
|
with pytest.raises(ValueError):
|
2019-06-23 06:32:27 +02:00
|
|
|
module.parse_arguments('--stats', 'list')
|
|
|
|
|
|
|
|
|
2022-08-21 23:25:16 +02:00
|
|
|
def test_parse_arguments_with_list_and_create_flags_does_not_raise():
|
2020-01-11 16:38:07 +01:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2022-08-21 23:25:16 +02:00
|
|
|
module.parse_arguments('--list', 'create')
|
2020-01-11 16:38:07 +01:00
|
|
|
|
|
|
|
|
2022-08-21 23:25:16 +02:00
|
|
|
def test_parse_arguments_with_list_and_prune_flags_does_not_raise():
|
2020-01-11 16:38:07 +01:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
2022-08-21 23:25:16 +02:00
|
|
|
module.parse_arguments('--list', 'prune')
|
2020-01-11 16:38:07 +01:00
|
|
|
|
|
|
|
|
2022-08-21 23:25:16 +02:00
|
|
|
def test_parse_arguments_with_list_flag_but_no_relevant_action_raises_value_error():
|
2020-01-11 16:38:07 +01:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit):
|
2022-08-21 23:25:16 +02:00
|
|
|
module.parse_arguments('--list', 'rcreate')
|
2020-01-11 16:38:07 +01:00
|
|
|
|
|
|
|
|
2023-02-27 02:05:56 +01:00
|
|
|
def test_parse_arguments_disallows_list_with_progress_for_create_action():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments('create', '--list', '--progress')
|
|
|
|
|
|
|
|
|
2023-05-04 02:16:36 +02:00
|
|
|
def test_parse_arguments_disallows_list_with_json_for_create_action():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments('create', '--list', '--json')
|
|
|
|
|
|
|
|
|
2019-06-23 06:32:27 +02:00
|
|
|
def test_parse_arguments_allows_json_with_list_or_info():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('list', '--json')
|
|
|
|
module.parse_arguments('info', '--json')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_disallows_json_with_both_list_and_info():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments('list', 'info', '--json')
|
2019-09-20 20:43:27 +02:00
|
|
|
|
|
|
|
|
2022-08-13 08:06:56 +02:00
|
|
|
def test_parse_arguments_disallows_json_with_both_list_and_rinfo():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments('list', 'rinfo', '--json')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_disallows_json_with_both_rinfo_and_info():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments('rinfo', 'info', '--json')
|
|
|
|
|
|
|
|
|
2022-10-04 07:50:37 +02:00
|
|
|
def test_parse_arguments_disallows_transfer_with_both_archive_and_match_archives():
|
2022-08-19 18:40:29 +02:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments(
|
|
|
|
'transfer',
|
|
|
|
'--source-repository',
|
|
|
|
'source.borg',
|
|
|
|
'--archive',
|
|
|
|
'foo',
|
2022-10-04 07:50:37 +02:00
|
|
|
'--match-archives',
|
|
|
|
'sh:*bar',
|
2022-08-19 18:40:29 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-04-05 06:25:10 +02:00
|
|
|
def test_parse_arguments_disallows_list_with_both_prefix_and_match_archives():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments('list', '--prefix', 'foo', '--match-archives', 'sh:*bar')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_disallows_rlist_with_both_prefix_and_match_archives():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments('rlist', '--prefix', 'foo', '--match-archives', 'sh:*bar')
|
|
|
|
|
|
|
|
|
2022-10-04 07:50:37 +02:00
|
|
|
def test_parse_arguments_disallows_info_with_both_archive_and_match_archives():
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
2022-10-04 07:50:37 +02:00
|
|
|
module.parse_arguments('info', '--archive', 'foo', '--match-archives', 'sh:*bar')
|
2022-08-12 23:53:20 +02:00
|
|
|
|
|
|
|
|
2022-08-18 00:36:19 +02:00
|
|
|
def test_parse_arguments_disallows_info_with_both_archive_and_prefix():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments('info', '--archive', 'foo', '--prefix', 'bar')
|
|
|
|
|
|
|
|
|
2022-10-04 07:50:37 +02:00
|
|
|
def test_parse_arguments_disallows_info_with_both_prefix_and_match_archives():
|
2022-08-18 00:36:19 +02:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
2022-10-04 07:50:37 +02:00
|
|
|
module.parse_arguments('info', '--prefix', 'foo', '--match-archives', 'sh:*bar')
|
2022-08-18 00:36:19 +02:00
|
|
|
|
|
|
|
|
2019-09-20 20:43:27 +02:00
|
|
|
def test_parse_arguments_check_only_extract_does_not_raise_extract_subparser_error():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('check', '--only', 'extract')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_extract_archive_check_does_not_raise_check_subparser_error():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('extract', '--archive', 'check')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_extract_with_check_only_extract_does_not_raise():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('extract', '--archive', 'name', 'check', '--only', 'extract')
|
2023-06-09 00:45:18 +02:00
|
|
|
|
|
|
|
|
2023-06-20 01:18:47 +02:00
|
|
|
def test_parse_arguments_bootstrap_without_config_errors():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
2023-06-09 00:45:18 +02:00
|
|
|
|
2023-06-24 23:10:47 +02:00
|
|
|
with pytest.raises(ValueError):
|
2023-06-20 01:18:47 +02:00
|
|
|
module.parse_arguments('bootstrap')
|
2023-06-09 00:45:18 +02:00
|
|
|
|
|
|
|
|
2023-06-20 01:18:47 +02:00
|
|
|
def test_parse_arguments_config_with_no_subaction_errors():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments('config')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_config_with_help_shows_config_help(capsys):
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit) as exit:
|
|
|
|
module.parse_arguments('config', '--help')
|
|
|
|
|
|
|
|
assert exit.value.code == 0
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert 'global arguments:' not in captured.out
|
|
|
|
assert 'config arguments:' in captured.out
|
|
|
|
assert 'config sub-actions:' in captured.out
|
|
|
|
|
|
|
|
|
2023-06-21 19:47:53 +02:00
|
|
|
def test_parse_arguments_config_with_subaction_but_missing_flags_errors():
|
2023-06-20 01:18:47 +02:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit) as exit:
|
|
|
|
module.parse_arguments('config', 'bootstrap')
|
|
|
|
|
|
|
|
assert exit.value.code == 2
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_config_with_subaction_and_help_shows_subaction_help(capsys):
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit) as exit:
|
|
|
|
module.parse_arguments('config', 'bootstrap', '--help')
|
|
|
|
|
|
|
|
assert exit.value.code == 0
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert 'config bootstrap arguments:' in captured.out
|
|
|
|
|
|
|
|
|
2023-06-21 19:47:53 +02:00
|
|
|
def test_parse_arguments_config_with_subaction_and_required_flags_does_not_raise():
|
2023-06-20 01:18:47 +02:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('config', 'bootstrap', '--repository', 'repo.borg')
|
|
|
|
|
|
|
|
|
2023-06-21 19:47:53 +02:00
|
|
|
def test_parse_arguments_config_with_subaction_and_global_flags_at_start_does_not_raise():
|
2023-06-20 01:18:47 +02:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
2023-06-09 00:45:18 +02:00
|
|
|
|
2023-06-20 01:18:47 +02:00
|
|
|
module.parse_arguments('--verbosity', '1', 'config', 'bootstrap', '--repository', 'repo.borg')
|
2023-06-21 19:41:32 +02:00
|
|
|
|
|
|
|
|
2023-06-21 19:47:53 +02:00
|
|
|
def test_parse_arguments_config_with_subaction_and_global_flags_at_end_does_not_raise():
|
2023-06-21 19:41:32 +02:00
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('config', 'bootstrap', '--repository', 'repo.borg', '--verbosity', '1')
|
2023-06-21 19:47:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_config_with_subaction_and_explicit_config_file_does_not_raise():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments(
|
|
|
|
'config', 'bootstrap', '--repository', 'repo.borg', '--config', 'test.yaml'
|
|
|
|
)
|
2023-10-24 02:23:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_borg_action_and_dry_run_raises():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_arguments('--dry-run', 'borg', 'list')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_arguments_with_borg_action_and_no_dry_run_does_not_raise():
|
|
|
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
|
|
|
|
|
|
|
module.parse_arguments('borg', 'list')
|