2022-06-04 00:12:14 +02:00
|
|
|
import argparse
|
2018-09-08 22:53:37 +02:00
|
|
|
import logging
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2019-06-25 19:18:30 +02:00
|
|
|
import pytest
|
2018-05-27 01:09:08 +02:00
|
|
|
from flexmock import flexmock
|
|
|
|
|
|
|
|
from borgmatic.borg import list as module
|
|
|
|
|
2019-05-13 23:39:10 +02:00
|
|
|
from ..test_verbosity import insert_logging_mock
|
2018-05-27 01:09:08 +02:00
|
|
|
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
def test_make_list_command_includes_log_info():
|
|
|
|
insert_logging_mock(logging.INFO)
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
command = module.make_list_command(
|
2019-10-14 00:58:11 +02:00
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-03 05:35:39 +02:00
|
|
|
list_arguments=flexmock(archive=None, paths=None, json=False),
|
2019-06-25 19:18:30 +02:00
|
|
|
)
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
assert command == ('borg', 'list', '--info', 'repo')
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
|
|
|
|
def test_make_list_command_includes_json_but_not_info():
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.INFO)
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--json',))
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
command = module.make_list_command(
|
2019-10-14 00:58:11 +02:00
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-04 00:12:14 +02:00
|
|
|
list_arguments=flexmock(archive=None, paths=None, json=True),
|
2019-06-25 19:18:30 +02:00
|
|
|
)
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
assert command == ('borg', 'list', '--json', 'repo')
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2019-06-13 19:01:55 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
def test_make_list_command_includes_log_debug():
|
|
|
|
insert_logging_mock(logging.DEBUG)
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2022-06-04 00:12:14 +02:00
|
|
|
|
|
|
|
command = module.make_list_command(
|
2019-10-14 00:58:11 +02:00
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-04 00:12:14 +02:00
|
|
|
list_arguments=flexmock(archive=None, paths=None, json=False),
|
2019-06-25 19:18:30 +02:00
|
|
|
)
|
2019-06-13 19:01:55 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
assert command == ('borg', 'list', '--debug', '--show-rc', 'repo')
|
2019-06-13 19:01:55 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
|
|
|
|
def test_make_list_command_includes_json_but_not_debug():
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.DEBUG)
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--json',))
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
command = module.make_list_command(
|
2019-10-14 00:58:11 +02:00
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-04 00:12:14 +02:00
|
|
|
list_arguments=flexmock(archive=None, paths=None, json=True),
|
2019-06-25 19:18:30 +02:00
|
|
|
)
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
assert command == ('borg', 'list', '--json', 'repo')
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2019-06-13 19:01:55 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
def test_make_list_command_includes_json():
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--json',))
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
command = module.make_list_command(
|
2019-10-14 00:58:11 +02:00
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-03 05:35:39 +02:00
|
|
|
list_arguments=flexmock(archive=None, paths=None, json=True),
|
2019-06-25 19:18:30 +02:00
|
|
|
)
|
2019-06-13 19:01:55 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
assert command == ('borg', 'list', '--json', 'repo')
|
2019-06-13 19:01:55 +02:00
|
|
|
|
2018-07-28 23:21:38 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
def test_make_list_command_includes_lock_wait():
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(
|
|
|
|
('--lock-wait', '5')
|
|
|
|
)
|
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
command = module.make_list_command(
|
2019-06-25 19:18:30 +02:00
|
|
|
repository='repo',
|
2022-06-04 00:12:14 +02:00
|
|
|
storage_config={'lock_wait': 5},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-03 05:35:39 +02:00
|
|
|
list_arguments=flexmock(archive=None, paths=None, json=False),
|
2019-06-25 19:18:30 +02:00
|
|
|
)
|
2019-02-24 08:02:17 +01:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
assert command == ('borg', 'list', '--lock-wait', '5', 'repo')
|
2019-02-24 08:02:17 +01:00
|
|
|
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
def test_make_list_command_includes_archive():
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
('repo::archive',)
|
|
|
|
)
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
command = module.make_list_command(
|
2019-06-25 19:18:30 +02:00
|
|
|
repository='repo',
|
2022-06-04 00:12:14 +02:00
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-03 05:35:39 +02:00
|
|
|
list_arguments=flexmock(archive='archive', paths=None, json=False),
|
2019-12-08 23:07:02 +01:00
|
|
|
)
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
assert command == ('borg', 'list', 'repo::archive')
|
2019-12-08 23:07:02 +01:00
|
|
|
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
def test_make_list_command_includes_archive_and_path():
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
('repo::archive',)
|
|
|
|
)
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
command = module.make_list_command(
|
2019-12-08 23:07:02 +01:00
|
|
|
repository='repo',
|
2022-06-04 00:12:14 +02:00
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-03 05:35:39 +02:00
|
|
|
list_arguments=flexmock(archive='archive', paths=['var/lib'], json=False),
|
2019-06-25 19:18:30 +02:00
|
|
|
)
|
2018-07-28 23:21:38 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
assert command == ('borg', 'list', 'repo::archive', 'var/lib')
|
2018-07-28 23:21:38 +02:00
|
|
|
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
def test_make_list_command_includes_local_path():
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
command = module.make_list_command(
|
2019-06-25 19:18:30 +02:00
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-03 05:35:39 +02:00
|
|
|
list_arguments=flexmock(archive=None, paths=None, json=False),
|
2022-06-04 00:12:14 +02:00
|
|
|
local_path='borg2',
|
2019-06-25 19:18:30 +02:00
|
|
|
)
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
assert command == ('borg2', 'list', 'repo')
|
2018-05-27 01:09:08 +02:00
|
|
|
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
def test_make_list_command_includes_remote_path():
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(
|
|
|
|
('--remote-path', 'borg2')
|
|
|
|
).and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
command = module.make_list_command(
|
2019-06-25 19:18:30 +02:00
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-03 05:35:39 +02:00
|
|
|
list_arguments=flexmock(archive=None, paths=None, json=False),
|
2022-06-04 00:12:14 +02:00
|
|
|
remote_path='borg2',
|
2019-06-25 19:18:30 +02:00
|
|
|
)
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
assert command == ('borg', 'list', '--remote-path', 'borg2', 'repo')
|
2019-06-25 19:18:30 +02:00
|
|
|
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
def test_make_list_command_includes_short():
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--short',))
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
command = module.make_list_command(
|
2019-06-25 19:18:30 +02:00
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-03 05:35:39 +02:00
|
|
|
list_arguments=flexmock(archive=None, paths=None, json=False, short=True),
|
2019-06-25 19:18:30 +02:00
|
|
|
)
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
assert command == ('borg', 'list', '--short', 'repo')
|
|
|
|
|
2019-06-25 19:18:30 +02:00
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'argument_name',
|
|
|
|
(
|
|
|
|
'prefix',
|
2022-10-04 07:50:37 +02:00
|
|
|
'match_archives',
|
2019-06-25 19:18:30 +02:00
|
|
|
'sort_by',
|
|
|
|
'first',
|
|
|
|
'last',
|
|
|
|
'exclude',
|
|
|
|
'exclude_from',
|
|
|
|
'pattern',
|
2019-10-23 07:42:36 +02:00
|
|
|
'patterns_from',
|
2019-06-25 19:18:30 +02:00
|
|
|
),
|
|
|
|
)
|
2022-06-04 00:12:14 +02:00
|
|
|
def test_make_list_command_includes_additional_flags(argument_name):
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
|
|
|
|
(f"--{argument_name.replace('_', '-')}", 'value')
|
|
|
|
)
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
command = module.make_list_command(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-04 00:12:14 +02:00
|
|
|
list_arguments=flexmock(
|
|
|
|
archive=None,
|
|
|
|
paths=None,
|
|
|
|
json=False,
|
|
|
|
find_paths=None,
|
|
|
|
format=None,
|
2022-08-16 00:04:40 +02:00
|
|
|
**{argument_name: 'value'},
|
2022-06-04 00:12:14 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
assert command == ('borg', 'list', '--' + argument_name.replace('_', '-'), 'value', 'repo')
|
|
|
|
|
|
|
|
|
2022-06-04 00:20:05 +02:00
|
|
|
def test_make_find_paths_considers_none_as_empty_paths():
|
|
|
|
assert module.make_find_paths(None) == ()
|
2022-06-04 00:12:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_make_find_paths_passes_through_patterns():
|
|
|
|
find_paths = (
|
|
|
|
'fm:*',
|
|
|
|
'sh:**/*.txt',
|
|
|
|
're:^.*$',
|
|
|
|
'pp:root/somedir',
|
|
|
|
'pf:root/foo.txt',
|
|
|
|
'R /',
|
|
|
|
'r /',
|
|
|
|
'p /',
|
|
|
|
'P /',
|
|
|
|
'+ /',
|
|
|
|
'- /',
|
|
|
|
'! /',
|
|
|
|
)
|
|
|
|
|
|
|
|
assert module.make_find_paths(find_paths) == find_paths
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_find_paths_adds_globs_to_path_fragments():
|
|
|
|
assert module.make_find_paths(('foo.txt',)) == ('sh:**/*foo.txt*/**',)
|
|
|
|
|
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
def test_list_archive_calls_borg_with_parameters():
|
2022-08-18 18:59:48 +02:00
|
|
|
list_arguments = argparse.Namespace(
|
|
|
|
archive='archive',
|
|
|
|
paths=None,
|
|
|
|
json=False,
|
|
|
|
find_paths=None,
|
|
|
|
prefix=None,
|
2022-10-04 07:50:37 +02:00
|
|
|
match_archives=None,
|
2022-08-18 18:59:48 +02:00
|
|
|
sort_by=None,
|
|
|
|
first=None,
|
|
|
|
last=None,
|
|
|
|
)
|
2022-06-04 00:12:14 +02:00
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(False)
|
2022-06-04 00:12:14 +02:00
|
|
|
flexmock(module).should_receive('make_list_command').with_args(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-04 00:12:14 +02:00
|
|
|
list_arguments=list_arguments,
|
|
|
|
local_path='borg',
|
|
|
|
remote_path=None,
|
2022-08-16 00:04:40 +02:00
|
|
|
).and_return(('borg', 'list', 'repo::archive'))
|
2022-06-04 00:12:14 +02:00
|
|
|
flexmock(module).should_receive('make_find_paths').and_return(())
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2019-06-25 19:18:30 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2022-08-16 00:04:40 +02:00
|
|
|
('borg', 'list', 'repo::archive'),
|
2022-06-30 22:42:17 +02:00
|
|
|
output_log_level=logging.WARNING,
|
|
|
|
borg_local_path='borg',
|
|
|
|
extra_environment=None,
|
2022-06-04 00:12:14 +02:00
|
|
|
).once()
|
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
module.list_archive(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
list_arguments=list_arguments,
|
2022-06-04 00:12:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-08-16 00:40:28 +02:00
|
|
|
def test_list_archive_with_archive_and_json_errors():
|
2022-08-16 00:04:40 +02:00
|
|
|
list_arguments = argparse.Namespace(archive='archive', paths=None, json=True, find_paths=None)
|
2022-06-04 00:12:14 +02:00
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(False)
|
2019-06-25 19:18:30 +02:00
|
|
|
|
2022-08-16 00:40:28 +02:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.list_archive(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
list_arguments=list_arguments,
|
|
|
|
)
|
2022-06-04 00:12:14 +02:00
|
|
|
|
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
def test_list_archive_calls_borg_with_local_path():
|
2022-08-18 18:59:48 +02:00
|
|
|
list_arguments = argparse.Namespace(
|
|
|
|
archive='archive',
|
|
|
|
paths=None,
|
|
|
|
json=False,
|
|
|
|
find_paths=None,
|
|
|
|
prefix=None,
|
2022-10-04 07:50:37 +02:00
|
|
|
match_archives=None,
|
2022-08-18 18:59:48 +02:00
|
|
|
sort_by=None,
|
|
|
|
first=None,
|
|
|
|
last=None,
|
|
|
|
)
|
2022-06-04 00:12:14 +02:00
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(False)
|
2022-06-04 00:12:14 +02:00
|
|
|
flexmock(module).should_receive('make_list_command').with_args(
|
2019-06-25 19:18:30 +02:00
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-06-04 00:12:14 +02:00
|
|
|
list_arguments=list_arguments,
|
|
|
|
local_path='borg2',
|
|
|
|
remote_path=None,
|
2022-08-16 00:04:40 +02:00
|
|
|
).and_return(('borg2', 'list', 'repo::archive'))
|
2022-06-04 00:12:14 +02:00
|
|
|
flexmock(module).should_receive('make_find_paths').and_return(())
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2022-06-04 00:12:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2022-08-16 00:04:40 +02:00
|
|
|
('borg2', 'list', 'repo::archive'),
|
2022-06-30 22:42:17 +02:00
|
|
|
output_log_level=logging.WARNING,
|
|
|
|
borg_local_path='borg2',
|
|
|
|
extra_environment=None,
|
2022-06-04 00:12:14 +02:00
|
|
|
).once()
|
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
module.list_archive(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
list_arguments=list_arguments,
|
|
|
|
local_path='borg2',
|
2019-06-25 19:18:30 +02:00
|
|
|
)
|
2018-05-27 01:09:08 +02:00
|
|
|
|
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
def test_list_archive_calls_borg_multiple_times_with_find_paths():
|
2022-06-04 00:12:14 +02:00
|
|
|
glob_paths = ('**/*foo.txt*/**',)
|
|
|
|
list_arguments = argparse.Namespace(
|
2022-08-16 00:04:40 +02:00
|
|
|
archive=None,
|
|
|
|
json=False,
|
|
|
|
find_paths=['foo.txt'],
|
|
|
|
prefix=None,
|
2022-10-04 07:50:37 +02:00
|
|
|
match_archives=None,
|
2022-08-16 00:04:40 +02:00
|
|
|
sort_by=None,
|
|
|
|
first=None,
|
|
|
|
last=None,
|
2022-06-04 00:12:14 +02:00
|
|
|
)
|
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(False)
|
|
|
|
flexmock(module.rlist).should_receive('make_rlist_command').and_return(('borg', 'list', 'repo'))
|
2022-10-15 01:19:26 +02:00
|
|
|
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
|
|
|
('borg', 'list', 'repo'), extra_environment=None,
|
2022-08-18 18:59:48 +02:00
|
|
|
).and_return('archive1\narchive2').once()
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module).should_receive('make_list_command').and_return(
|
|
|
|
('borg', 'list', 'repo::archive1')
|
|
|
|
).and_return(('borg', 'list', 'repo::archive2'))
|
|
|
|
flexmock(module).should_receive('make_find_paths').and_return(glob_paths)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2022-06-04 00:12:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'list', 'repo::archive1') + glob_paths,
|
|
|
|
output_log_level=logging.WARNING,
|
|
|
|
borg_local_path='borg',
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2022-06-04 00:12:14 +02:00
|
|
|
).once()
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'list', 'repo::archive2') + glob_paths,
|
|
|
|
output_log_level=logging.WARNING,
|
|
|
|
borg_local_path='borg',
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2022-06-04 00:12:14 +02:00
|
|
|
).once()
|
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
module.list_archive(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
list_arguments=list_arguments,
|
2022-06-04 00:12:14 +02:00
|
|
|
)
|
|
|
|
|
2019-04-03 07:30:14 +02:00
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
def test_list_archive_calls_borg_with_archive():
|
2022-08-18 18:59:48 +02:00
|
|
|
list_arguments = argparse.Namespace(
|
|
|
|
archive='archive',
|
|
|
|
paths=None,
|
|
|
|
json=False,
|
|
|
|
find_paths=None,
|
|
|
|
prefix=None,
|
2022-10-04 07:50:37 +02:00
|
|
|
match_archives=None,
|
2022-08-18 18:59:48 +02:00
|
|
|
sort_by=None,
|
|
|
|
first=None,
|
|
|
|
last=None,
|
|
|
|
)
|
2022-06-04 00:12:14 +02:00
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(False)
|
|
|
|
flexmock(module).should_receive('make_list_command').with_args(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
list_arguments=list_arguments,
|
|
|
|
local_path='borg',
|
|
|
|
remote_path=None,
|
|
|
|
).and_return(('borg', 'list', 'repo::archive'))
|
|
|
|
flexmock(module).should_receive('make_find_paths').and_return(())
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'list', 'repo::archive'),
|
|
|
|
output_log_level=logging.WARNING,
|
|
|
|
borg_local_path='borg',
|
|
|
|
extra_environment=None,
|
|
|
|
).once()
|
|
|
|
|
|
|
|
module.list_archive(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
list_arguments=list_arguments,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_archive_without_archive_delegates_to_list_repository():
|
|
|
|
list_arguments = argparse.Namespace(
|
|
|
|
archive=None,
|
|
|
|
short=None,
|
|
|
|
format=None,
|
|
|
|
json=None,
|
|
|
|
prefix=None,
|
2022-10-04 07:50:37 +02:00
|
|
|
match_archives=None,
|
2022-08-16 00:04:40 +02:00
|
|
|
sort_by=None,
|
|
|
|
first=None,
|
|
|
|
last=None,
|
|
|
|
find_paths=None,
|
|
|
|
)
|
|
|
|
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(False)
|
|
|
|
flexmock(module.rlist).should_receive('list_repository')
|
|
|
|
flexmock(module.environment).should_receive('make_environment').never()
|
|
|
|
flexmock(module).should_receive('execute_command').never()
|
|
|
|
|
|
|
|
module.list_archive(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
list_arguments=list_arguments,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_archive_with_borg_features_without_archive_delegates_to_list_repository():
|
|
|
|
list_arguments = argparse.Namespace(
|
|
|
|
archive=None,
|
|
|
|
short=None,
|
|
|
|
format=None,
|
|
|
|
json=None,
|
|
|
|
prefix=None,
|
2022-10-04 07:50:37 +02:00
|
|
|
match_archives=None,
|
2022-08-16 00:04:40 +02:00
|
|
|
sort_by=None,
|
|
|
|
first=None,
|
|
|
|
last=None,
|
|
|
|
find_paths=None,
|
|
|
|
)
|
|
|
|
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module.rlist).should_receive('list_repository')
|
|
|
|
flexmock(module.environment).should_receive('make_environment').never()
|
|
|
|
flexmock(module).should_receive('execute_command').never()
|
|
|
|
|
|
|
|
module.list_archive(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
list_arguments=list_arguments,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2022-10-04 07:50:37 +02:00
|
|
|
'archive_filter_flag', ('prefix', 'match_archives', 'sort_by', 'first', 'last',),
|
2022-08-16 00:04:40 +02:00
|
|
|
)
|
2022-08-18 18:59:48 +02:00
|
|
|
def test_list_archive_with_archive_ignores_archive_filter_flag(archive_filter_flag,):
|
|
|
|
default_filter_flags = {
|
|
|
|
'prefix': None,
|
2022-10-04 07:50:37 +02:00
|
|
|
'match_archives': None,
|
2022-08-18 18:59:48 +02:00
|
|
|
'sort_by': None,
|
|
|
|
'first': None,
|
|
|
|
'last': None,
|
|
|
|
}
|
|
|
|
altered_filter_flags = {**default_filter_flags, **{archive_filter_flag: 'foo'}}
|
2022-08-16 00:04:40 +02:00
|
|
|
|
|
|
|
flexmock(module.feature).should_receive('available').with_args(
|
|
|
|
module.feature.Feature.RLIST, '1.2.3'
|
2022-08-18 18:59:48 +02:00
|
|
|
).and_return(False)
|
|
|
|
flexmock(module).should_receive('make_list_command').with_args(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
list_arguments=argparse.Namespace(
|
|
|
|
archive='archive', paths=None, json=False, find_paths=None, **default_filter_flags
|
|
|
|
),
|
|
|
|
local_path='borg',
|
|
|
|
remote_path=None,
|
|
|
|
).and_return(('borg', 'list', 'repo::archive'))
|
|
|
|
flexmock(module).should_receive('make_find_paths').and_return(())
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'list', 'repo::archive'),
|
|
|
|
output_log_level=logging.WARNING,
|
|
|
|
borg_local_path='borg',
|
|
|
|
extra_environment=None,
|
|
|
|
).once()
|
2022-08-16 00:04:40 +02:00
|
|
|
|
2022-08-18 18:59:48 +02:00
|
|
|
module.list_archive(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
list_arguments=argparse.Namespace(
|
|
|
|
archive='archive', paths=None, json=False, find_paths=None, **altered_filter_flags
|
|
|
|
),
|
|
|
|
)
|
2022-08-16 00:04:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2022-10-04 07:50:37 +02:00
|
|
|
'archive_filter_flag', ('prefix', 'match_archives', 'sort_by', 'first', 'last',),
|
2022-08-16 00:04:40 +02:00
|
|
|
)
|
2022-08-18 18:59:48 +02:00
|
|
|
def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes_it_to_rlist(
|
2022-08-16 00:04:40 +02:00
|
|
|
archive_filter_flag,
|
|
|
|
):
|
2022-08-18 18:59:48 +02:00
|
|
|
default_filter_flags = {
|
|
|
|
'prefix': None,
|
2022-10-04 07:50:37 +02:00
|
|
|
'match_archives': None,
|
2022-08-18 18:59:48 +02:00
|
|
|
'sort_by': None,
|
|
|
|
'first': None,
|
|
|
|
'last': None,
|
|
|
|
}
|
|
|
|
altered_filter_flags = {**default_filter_flags, **{archive_filter_flag: 'foo'}}
|
|
|
|
glob_paths = ('**/*foo.txt*/**',)
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
|
|
|
|
flexmock(module.rlist).should_receive('make_rlist_command').with_args(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
rlist_arguments=argparse.Namespace(
|
|
|
|
repository='repo', short=True, format=None, json=None, **altered_filter_flags
|
|
|
|
),
|
|
|
|
local_path='borg',
|
|
|
|
remote_path=None,
|
|
|
|
).and_return(('borg', 'rlist', '--repo', 'repo'))
|
|
|
|
|
2022-10-15 01:19:26 +02:00
|
|
|
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
|
|
|
('borg', 'rlist', '--repo', 'repo'), extra_environment=None,
|
2022-08-18 18:59:48 +02:00
|
|
|
).and_return('archive1\narchive2').once()
|
2022-08-16 00:04:40 +02:00
|
|
|
|
2022-06-04 00:12:14 +02:00
|
|
|
flexmock(module).should_receive('make_list_command').with_args(
|
2019-10-14 00:58:11 +02:00
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
2022-08-16 00:04:40 +02:00
|
|
|
local_borg_version='1.2.3',
|
2022-08-18 18:59:48 +02:00
|
|
|
list_arguments=argparse.Namespace(
|
|
|
|
repository='repo',
|
|
|
|
archive='archive1',
|
|
|
|
paths=None,
|
|
|
|
short=True,
|
|
|
|
format=None,
|
|
|
|
json=None,
|
|
|
|
find_paths=['foo.txt'],
|
|
|
|
**default_filter_flags,
|
|
|
|
),
|
2022-06-04 00:12:14 +02:00
|
|
|
local_path='borg',
|
|
|
|
remote_path=None,
|
2022-08-18 18:59:48 +02:00
|
|
|
).and_return(('borg', 'list', '--repo', 'repo', 'archive1'))
|
|
|
|
|
|
|
|
flexmock(module).should_receive('make_list_command').with_args(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
list_arguments=argparse.Namespace(
|
|
|
|
repository='repo',
|
|
|
|
archive='archive2',
|
|
|
|
paths=None,
|
|
|
|
short=True,
|
|
|
|
format=None,
|
|
|
|
json=None,
|
|
|
|
find_paths=['foo.txt'],
|
|
|
|
**default_filter_flags,
|
|
|
|
),
|
|
|
|
local_path='borg',
|
|
|
|
remote_path=None,
|
|
|
|
).and_return(('borg', 'list', '--repo', 'repo', 'archive2'))
|
|
|
|
|
|
|
|
flexmock(module).should_receive('make_find_paths').and_return(glob_paths)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2022-06-04 00:12:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2022-08-18 18:59:48 +02:00
|
|
|
('borg', 'list', '--repo', 'repo', 'archive1') + glob_paths,
|
|
|
|
output_log_level=logging.WARNING,
|
|
|
|
borg_local_path='borg',
|
|
|
|
extra_environment=None,
|
|
|
|
).once()
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'list', '--repo', 'repo', 'archive2') + glob_paths,
|
2022-06-30 22:42:17 +02:00
|
|
|
output_log_level=logging.WARNING,
|
|
|
|
borg_local_path='borg',
|
|
|
|
extra_environment=None,
|
2022-06-04 00:12:14 +02:00
|
|
|
).once()
|
2018-05-27 01:09:08 +02:00
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
module.list_archive(
|
|
|
|
repository='repo',
|
|
|
|
storage_config={},
|
|
|
|
local_borg_version='1.2.3',
|
2022-08-18 18:59:48 +02:00
|
|
|
list_arguments=argparse.Namespace(
|
|
|
|
repository='repo',
|
|
|
|
archive=None,
|
|
|
|
paths=None,
|
|
|
|
short=True,
|
|
|
|
format=None,
|
|
|
|
json=None,
|
|
|
|
find_paths=['foo.txt'],
|
|
|
|
**altered_filter_flags,
|
|
|
|
),
|
2022-06-04 00:12:14 +02:00
|
|
|
)
|