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