2018-09-30 08:15:18 +02:00
|
|
|
import logging
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
import pytest
|
2019-05-13 23:39:10 +02:00
|
|
|
from flexmock import flexmock
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
from borgmatic.borg import check as module
|
2019-05-13 23:39:10 +02:00
|
|
|
|
2018-09-30 22:57:20 +02:00
|
|
|
from ..test_verbosity import insert_logging_mock
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2018-09-30 07:45:00 +02:00
|
|
|
|
2024-01-21 20:34:40 +01:00
|
|
|
def insert_execute_command_mock(command, borg_exit_codes=None):
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2024-01-21 20:34:40 +01:00
|
|
|
command,
|
|
|
|
extra_environment=None,
|
|
|
|
borg_local_path=command[0],
|
|
|
|
borg_exit_codes=borg_exit_codes,
|
2022-06-30 22:42:17 +02:00
|
|
|
).once()
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2019-06-13 05:56:20 +02:00
|
|
|
def insert_execute_command_never():
|
|
|
|
flexmock(module).should_receive('execute_command').never()
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_default_checks_and_prefix_returns_default_flags():
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
flags = module.make_archive_filter_flags(
|
2023-04-15 04:35:24 +02:00
|
|
|
'1.2.3',
|
2024-03-20 19:58:59 +01:00
|
|
|
{'prefix': 'foo'},
|
2023-04-15 04:35:24 +02:00
|
|
|
('repository', 'archives'),
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(match_archives=None),
|
2023-04-15 04:35:24 +02:00
|
|
|
)
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
assert flags == ('--match-archives', 'sh:foo*')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_all_checks_and_prefix_returns_default_flags():
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
flags = module.make_archive_filter_flags(
|
2023-04-15 04:35:24 +02:00
|
|
|
'1.2.3',
|
2024-03-20 19:58:59 +01:00
|
|
|
{'prefix': 'foo'},
|
2023-04-15 04:35:24 +02:00
|
|
|
('repository', 'archives', 'extract'),
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(match_archives=None),
|
2022-10-04 07:50:37 +02:00
|
|
|
)
|
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
assert flags == ('--match-archives', 'sh:foo*')
|
2022-10-04 07:50:37 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_all_checks_and_prefix_without_borg_features_returns_glob_archives_flags():
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(False)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
flags = module.make_archive_filter_flags(
|
2023-04-15 04:35:24 +02:00
|
|
|
'1.2.3',
|
2024-03-20 19:58:59 +01:00
|
|
|
{'prefix': 'foo'},
|
2023-04-15 04:35:24 +02:00
|
|
|
('repository', 'archives', 'extract'),
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(match_archives=None),
|
2019-07-27 23:08:47 +02:00
|
|
|
)
|
2018-01-14 23:09:20 +01:00
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
assert flags == ('--glob-archives', 'foo*')
|
2018-05-21 07:11:40 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_archives_check_and_last_includes_last_flag():
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
2024-04-04 23:23:56 +02:00
|
|
|
'1.2.3',
|
|
|
|
{'check_last': 3},
|
|
|
|
('archives',),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
2023-10-30 00:22:39 +01:00
|
|
|
)
|
2018-01-14 23:09:20 +01:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ('--last', '3')
|
2018-01-14 23:09:20 +01:00
|
|
|
|
2018-05-21 07:11:40 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_data_check_and_last_includes_last_flag():
|
2022-11-17 19:19:48 +01:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-11-17 19:19:48 +01:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
2024-04-04 23:23:56 +02:00
|
|
|
'1.2.3',
|
|
|
|
{'check_last': 3},
|
|
|
|
('data',),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
2023-10-30 00:22:39 +01:00
|
|
|
)
|
2022-11-17 19:19:48 +01:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ('--last', '3')
|
2022-11-17 19:19:48 +01:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_repository_check_and_last_omits_last_flag():
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
2024-04-04 23:23:56 +02:00
|
|
|
'1.2.3',
|
|
|
|
{'check_last': 3},
|
|
|
|
('repository',),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
2023-10-30 00:22:39 +01:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ()
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_default_checks_and_last_includes_last_flag():
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3',
|
2024-03-20 19:58:59 +01:00
|
|
|
{'check_last': 3},
|
2023-10-30 00:22:39 +01:00
|
|
|
('repository', 'archives'),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2019-07-27 23:04:13 +02:00
|
|
|
assert flags == ('--last', '3')
|
2018-05-21 07:11:40 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_archives_check_and_prefix_includes_match_archives_flag():
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
2024-04-04 23:23:56 +02:00
|
|
|
'1.2.3',
|
|
|
|
{'prefix': 'foo-'},
|
|
|
|
('archives',),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
2023-10-30 00:22:39 +01:00
|
|
|
)
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ('--match-archives', 'sh:foo-*')
|
2018-05-21 07:11:40 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_data_check_and_prefix_includes_match_archives_flag():
|
2022-11-17 19:19:48 +01:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-11-17 19:19:48 +01:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
2024-04-04 23:23:56 +02:00
|
|
|
'1.2.3',
|
|
|
|
{'prefix': 'foo-'},
|
|
|
|
('data',),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
2023-10-30 00:22:39 +01:00
|
|
|
)
|
2022-11-17 19:19:48 +01:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ('--match-archives', 'sh:foo-*')
|
2022-11-17 19:19:48 +01:00
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_make_archive_filter_flags_prefers_check_arguments_match_archives_to_config_match_archives():
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
|
|
|
'baz-*', None, '1.2.3'
|
|
|
|
).and_return(('--match-archives', 'sh:baz-*'))
|
|
|
|
|
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3',
|
2024-03-20 19:58:59 +01:00
|
|
|
{'match_archives': 'bar-{now}', 'prefix': ''}, # noqa: FS003
|
2023-10-30 00:22:39 +01:00
|
|
|
('archives',),
|
|
|
|
check_arguments=flexmock(match_archives='baz-*'),
|
|
|
|
)
|
|
|
|
|
|
|
|
assert flags == ('--match-archives', 'sh:baz-*')
|
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_archives_check_and_empty_prefix_uses_archive_name_format_instead():
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
2023-04-02 08:57:55 +02:00
|
|
|
None, 'bar-{now}', '1.2.3' # noqa: FS003
|
2023-04-01 00:21:08 +02:00
|
|
|
).and_return(('--match-archives', 'sh:bar-*'))
|
2018-05-21 07:11:40 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
flags = module.make_archive_filter_flags(
|
2023-10-30 00:22:39 +01:00
|
|
|
'1.2.3',
|
2024-03-20 19:58:59 +01:00
|
|
|
{'archive_name_format': 'bar-{now}', 'prefix': ''}, # noqa: FS003
|
2023-10-30 00:22:39 +01:00
|
|
|
('archives',),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
2023-04-01 00:21:08 +02:00
|
|
|
)
|
2019-07-27 23:04:13 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ('--match-archives', 'sh:bar-*')
|
2019-07-27 23:04:13 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_archives_check_and_none_prefix_omits_match_archives_flag():
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
2024-04-04 23:23:56 +02:00
|
|
|
'1.2.3',
|
|
|
|
{},
|
|
|
|
('archives',),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
2023-10-30 00:22:39 +01:00
|
|
|
)
|
2019-07-27 23:04:13 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ()
|
2019-07-27 23:04:13 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_repository_check_and_prefix_omits_match_archives_flag():
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
2024-04-04 23:23:56 +02:00
|
|
|
'1.2.3',
|
|
|
|
{'prefix': 'foo-'},
|
|
|
|
('repository',),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
2023-10-30 00:22:39 +01:00
|
|
|
)
|
2018-05-21 07:11:40 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ()
|
2018-05-21 07:11:40 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_default_checks_and_prefix_includes_match_archives_flag():
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3',
|
2024-03-20 19:58:59 +01:00
|
|
|
{'prefix': 'foo-'},
|
2023-10-30 00:22:39 +01:00
|
|
|
('repository', 'archives'),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
|
|
|
)
|
2018-05-21 07:11:40 +02:00
|
|
|
|
2022-10-04 07:50:37 +02:00
|
|
|
assert flags == ('--match-archives', 'sh:foo-*')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2024-06-23 01:19:06 +02:00
|
|
|
def test_make_check_name_flags_with_repository_check_returns_flag():
|
|
|
|
flags = module.make_check_name_flags({'repository'}, ())
|
2023-05-16 08:17:45 +02:00
|
|
|
|
|
|
|
assert flags == ('--repository-only',)
|
|
|
|
|
|
|
|
|
2024-06-23 01:19:06 +02:00
|
|
|
def test_make_check_name_flags_with_archives_check_returns_flag():
|
|
|
|
flags = module.make_check_name_flags({'archives'}, ())
|
2023-05-16 08:17:45 +02:00
|
|
|
|
|
|
|
assert flags == ('--archives-only',)
|
|
|
|
|
|
|
|
|
2024-06-23 01:19:06 +02:00
|
|
|
def test_make_check_name_flags_with_archives_check_and_archive_filter_flags_includes_those_flags():
|
|
|
|
flags = module.make_check_name_flags({'archives'}, ('--match-archives', 'sh:foo-*'))
|
2023-05-16 08:17:45 +02:00
|
|
|
|
|
|
|
assert flags == ('--archives-only', '--match-archives', 'sh:foo-*')
|
|
|
|
|
|
|
|
|
2024-06-23 01:19:06 +02:00
|
|
|
def test_make_check_name_flags_without_archives_check_and_with_archive_filter_flags_includes_those_flags():
|
|
|
|
flags = module.make_check_name_flags({'repository'}, ('--match-archives', 'sh:foo-*'))
|
2023-05-31 08:19:33 +02:00
|
|
|
|
|
|
|
assert flags == ('--repository-only',)
|
|
|
|
|
|
|
|
|
2024-06-23 01:19:06 +02:00
|
|
|
def test_make_check_name_flags_with_data_check_returns_flag_and_implies_archives():
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
|
|
|
|
2024-06-23 01:19:06 +02:00
|
|
|
flags = module.make_check_name_flags({'data'}, ())
|
2023-05-16 08:17:45 +02:00
|
|
|
|
|
|
|
assert flags == (
|
|
|
|
'--archives-only',
|
|
|
|
'--verify-data',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-06-23 01:19:06 +02:00
|
|
|
def test_make_check_name_flags_with_extract_omits_extract_flag():
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
|
|
|
|
2024-06-23 01:19:06 +02:00
|
|
|
flags = module.make_check_name_flags({'extract'}, ())
|
2023-05-16 08:17:45 +02:00
|
|
|
|
|
|
|
assert flags == ()
|
|
|
|
|
|
|
|
|
2024-06-23 01:19:06 +02:00
|
|
|
def test_make_check_name_flags_with_repository_and_data_checks_does_not_return_repository_only():
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
|
|
|
|
2024-06-23 01:19:06 +02:00
|
|
|
flags = module.make_check_name_flags(
|
2024-04-21 23:55:02 +02:00
|
|
|
{
|
2023-05-16 08:17:45 +02:00
|
|
|
'repository',
|
|
|
|
'data',
|
2024-04-21 23:55:02 +02:00
|
|
|
},
|
2023-05-16 08:17:45 +02:00
|
|
|
(),
|
|
|
|
)
|
|
|
|
|
|
|
|
assert flags == ('--verify-data',)
|
|
|
|
|
|
|
|
|
2024-03-20 19:58:59 +01:00
|
|
|
def test_get_repository_id_with_valid_json_does_not_raise():
|
|
|
|
config = {}
|
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
2023-05-16 08:17:45 +02:00
|
|
|
)
|
|
|
|
|
2024-03-20 19:58:59 +01:00
|
|
|
assert module.get_repository_id(
|
|
|
|
repository_path='repo',
|
|
|
|
config=config,
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
local_path='borg',
|
|
|
|
remote_path=None,
|
2023-05-16 08:17:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-03-20 19:58:59 +01:00
|
|
|
def test_get_repository_id_with_json_error_raises():
|
|
|
|
config = {}
|
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
|
|
|
'{"unexpected": {"id": "repo"}}'
|
2023-05-16 08:17:45 +02:00
|
|
|
)
|
|
|
|
|
2024-03-20 19:58:59 +01:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.get_repository_id(
|
|
|
|
repository_path='repo',
|
|
|
|
config=config,
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
local_path='borg',
|
|
|
|
remote_path=None,
|
2023-05-16 08:17:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-03-20 19:58:59 +01:00
|
|
|
def test_get_repository_id_with_missing_json_keys_raises():
|
|
|
|
config = {}
|
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return('{invalid JSON')
|
2023-05-16 08:17:45 +02:00
|
|
|
|
2024-03-20 19:58:59 +01:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.get_repository_id(
|
|
|
|
repository_path='repo',
|
|
|
|
config=config,
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
local_path='borg',
|
|
|
|
remote_path=None,
|
2023-05-16 08:17:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_progress_passes_through_to_borg():
|
2024-03-20 19:58:59 +01:00
|
|
|
config = {}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2020-05-10 06:53:16 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2022-06-30 22:42:17 +02:00
|
|
|
('borg', 'check', '--progress', 'repo'),
|
|
|
|
output_file=module.DO_NOT_CAPTURE,
|
|
|
|
extra_environment=None,
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
2020-01-24 20:27:16 +01:00
|
|
|
).once()
|
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=True,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks={'repository'},
|
|
|
|
archive_filter_flags=(),
|
2020-01-24 20:27:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_repair_passes_through_to_borg():
|
2024-03-20 19:58:59 +01:00
|
|
|
config = {}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2020-05-10 06:53:16 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2022-06-30 22:42:17 +02:00
|
|
|
('borg', 'check', '--repair', 'repo'),
|
|
|
|
output_file=module.DO_NOT_CAPTURE,
|
|
|
|
extra_environment=None,
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
2019-12-05 01:07:00 +01:00
|
|
|
).once()
|
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=None,
|
|
|
|
repair=True,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
|
|
|
),
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
checks={'repository'},
|
|
|
|
archive_filter_flags=(),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_max_duration_flag_passes_through_to_borg():
|
|
|
|
config = {}
|
|
|
|
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'check', '--max-duration', '33', 'repo'),
|
|
|
|
extra_environment=None,
|
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
|
|
|
).once()
|
|
|
|
|
|
|
|
module.check_archives(
|
|
|
|
repository_path='repo',
|
|
|
|
config=config,
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=33,
|
|
|
|
),
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
checks={'repository'},
|
|
|
|
archive_filter_flags=(),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_max_duration_flag_and_archives_check_errors():
|
|
|
|
config = {}
|
|
|
|
flexmock(module).should_receive('execute_command').never()
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.check_archives(
|
|
|
|
repository_path='repo',
|
|
|
|
config=config,
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=33,
|
|
|
|
),
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
checks={'repository', 'archives'},
|
|
|
|
archive_filter_flags=(),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_max_duration_option_passes_through_to_borg():
|
|
|
|
config = {'checks': [{'name': 'repository', 'max_duration': 33}]}
|
|
|
|
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'check', '--max-duration', '33', 'repo'),
|
|
|
|
extra_environment=None,
|
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
|
|
|
).once()
|
|
|
|
|
|
|
|
module.check_archives(
|
|
|
|
repository_path='repo',
|
|
|
|
config=config,
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
|
|
|
),
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
checks={'repository'},
|
|
|
|
archive_filter_flags=(),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_max_duration_option_and_archives_check_errors():
|
|
|
|
config = {'checks': [{'name': 'repository', 'max_duration': 33}]}
|
|
|
|
flexmock(module).should_receive('execute_command').never()
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.check_archives(
|
|
|
|
repository_path='repo',
|
|
|
|
config=config,
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
|
|
|
),
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
checks={'repository', 'archives'},
|
|
|
|
archive_filter_flags=(),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_max_duration_flag_overrides_max_duration_option():
|
|
|
|
config = {'checks': [{'name': 'repository', 'max_duration': 33}]}
|
|
|
|
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'check', '--max-duration', '44', 'repo'),
|
|
|
|
extra_environment=None,
|
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
|
|
|
).once()
|
|
|
|
|
|
|
|
module.check_archives(
|
|
|
|
repository_path='repo',
|
|
|
|
config=config,
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=44,
|
2023-10-30 00:22:39 +01:00
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks={'repository'},
|
|
|
|
archive_filter_flags=(),
|
2019-12-05 01:07:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-08-06 01:21:39 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'checks',
|
|
|
|
(
|
|
|
|
('repository',),
|
|
|
|
('archives',),
|
|
|
|
('repository', 'archives'),
|
|
|
|
('repository', 'archives', 'other'),
|
|
|
|
),
|
|
|
|
)
|
2018-01-15 01:35:24 +01:00
|
|
|
def test_check_archives_calls_borg_with_parameters(checks):
|
2024-03-20 19:58:59 +01:00
|
|
|
config = {}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'check', 'repo'))
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks=checks,
|
|
|
|
archive_filter_flags=(),
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_log_info_passes_through_to_borg():
|
2024-03-20 19:58:59 +01:00
|
|
|
config = {}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.INFO)
|
2019-09-13 00:27:04 +02:00
|
|
|
insert_execute_command_mock(('borg', 'check', '--info', 'repo'))
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks={'repository'},
|
|
|
|
archive_filter_flags=(),
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_log_debug_passes_through_to_borg():
|
2024-03-20 19:58:59 +01:00
|
|
|
config = {}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.DEBUG)
|
2019-09-13 00:27:04 +02:00
|
|
|
insert_execute_command_mock(('borg', 'check', '--debug', '--show-rc', 'repo'))
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks={'repository'},
|
|
|
|
archive_filter_flags=(),
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-01-15 01:35:24 +01:00
|
|
|
def test_check_archives_with_local_path_calls_borg_via_local_path():
|
2024-03-20 19:58:59 +01:00
|
|
|
checks = {'repository'}
|
|
|
|
config = {}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg1', 'check', 'repo'))
|
2018-01-15 01:35:24 +01:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks=checks,
|
|
|
|
archive_filter_flags=(),
|
2018-01-15 01:35:24 +01:00
|
|
|
local_path='borg1',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-01-21 20:34:40 +01:00
|
|
|
def test_check_archives_with_exit_codes_calls_borg_using_them():
|
2024-03-20 19:58:59 +01:00
|
|
|
checks = {'repository'}
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes = flexmock()
|
2024-03-20 19:58:59 +01:00
|
|
|
config = {'borg_exit_codes': borg_exit_codes}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
2024-01-21 20:34:40 +01:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
insert_execute_command_mock(('borg', 'check', 'repo'), borg_exit_codes=borg_exit_codes)
|
|
|
|
|
|
|
|
module.check_archives(
|
|
|
|
repository_path='repo',
|
|
|
|
config=config,
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
2024-01-21 20:34:40 +01:00
|
|
|
),
|
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks=checks,
|
|
|
|
archive_filter_flags=(),
|
2024-01-21 20:34:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_remote_path_passes_through_to_borg():
|
2024-03-20 19:58:59 +01:00
|
|
|
checks = {'repository'}
|
|
|
|
config = {}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-09-13 00:27:04 +02:00
|
|
|
insert_execute_command_mock(('borg', 'check', '--remote-path', 'borg1', 'repo'))
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks=checks,
|
|
|
|
archive_filter_flags=(),
|
2017-08-06 01:21:39 +02:00
|
|
|
remote_path='borg1',
|
|
|
|
)
|
2018-02-20 00:51:04 +01:00
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_log_json_passes_through_to_borg():
|
2024-03-20 19:58:59 +01:00
|
|
|
checks = {'repository'}
|
|
|
|
config = {}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
2023-05-09 08:00:49 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
insert_execute_command_mock(('borg', 'check', '--log-json', 'repo'))
|
|
|
|
|
|
|
|
module.check_archives(
|
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2023-05-09 08:00:49 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=True),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks=checks,
|
|
|
|
archive_filter_flags=(),
|
2023-05-09 08:00:49 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_lock_wait_passes_through_to_borg():
|
2024-03-20 19:58:59 +01:00
|
|
|
checks = {'repository'}
|
|
|
|
config = {'lock_wait': 5}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-09-13 00:27:04 +02:00
|
|
|
insert_execute_command_mock(('borg', 'check', '--lock-wait', '5', 'repo'))
|
2018-02-20 00:51:04 +01:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks=checks,
|
|
|
|
archive_filter_flags=(),
|
2018-02-20 00:51:04 +01:00
|
|
|
)
|
2018-03-04 07:17:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_retention_prefix():
|
2024-03-20 19:58:59 +01:00
|
|
|
checks = {'repository'}
|
2018-05-21 07:11:40 +02:00
|
|
|
prefix = 'foo-'
|
2024-03-20 19:58:59 +01:00
|
|
|
config = {'prefix': prefix}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'check', 'repo'))
|
2018-03-04 07:17:39 +01:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks=checks,
|
|
|
|
archive_filter_flags=(),
|
2018-03-04 07:17:39 +01:00
|
|
|
)
|
2019-12-05 00:48:10 +01:00
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_extra_borg_options_passes_through_to_borg():
|
2024-03-20 19:58:59 +01:00
|
|
|
config = {'extra_borg_options': {'check': '--extra --options'}}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-12-05 00:48:10 +01:00
|
|
|
insert_execute_command_mock(('borg', 'check', '--extra', '--options', 'repo'))
|
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives=None,
|
|
|
|
max_duration=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
),
|
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks={'repository'},
|
|
|
|
archive_filter_flags=(),
|
2023-10-30 00:22:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_match_archives_passes_through_to_borg():
|
2024-03-20 19:58:59 +01:00
|
|
|
config = {}
|
2024-06-23 01:19:06 +02:00
|
|
|
flexmock(module).should_receive('make_check_name_flags').and_return(
|
|
|
|
('--match-archives', 'foo-*')
|
|
|
|
)
|
2023-10-30 00:22:39 +01:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'check', '--match-archives', 'foo-*', 'repo'),
|
|
|
|
extra_environment=None,
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
).once()
|
|
|
|
|
|
|
|
module.check_archives(
|
|
|
|
repository_path='repo',
|
|
|
|
config=config,
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
check_arguments=flexmock(
|
2024-06-23 01:19:06 +02:00
|
|
|
progress=None,
|
|
|
|
repair=None,
|
|
|
|
only_checks=None,
|
|
|
|
force=None,
|
|
|
|
match_archives='foo-*',
|
|
|
|
max_duration=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-03-20 19:58:59 +01:00
|
|
|
checks={'archives'},
|
|
|
|
archive_filter_flags=('--match-archives', 'foo-*'),
|
2019-12-05 00:48:10 +01:00
|
|
|
)
|