|
@@ -117,6 +117,7 @@ def test_prune_archives_calls_borg_with_flags():
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('repo',), logging.INFO)
|
|
|
|
|
|
+ prune_arguments = flexmock(stats=False, list_archives=False)
|
|
|
module.prune_archives(
|
|
|
dry_run=False,
|
|
|
repository_path='repo',
|
|
@@ -124,6 +125,7 @@ def test_prune_archives_calls_borg_with_flags():
|
|
|
retention_config=flexmock(),
|
|
|
local_borg_version='1.2.3',
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -135,6 +137,7 @@ def test_prune_archives_with_log_info_calls_borg_with_info_flag():
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--info', 'repo'), logging.INFO)
|
|
|
insert_logging_mock(logging.INFO)
|
|
|
|
|
|
+ prune_arguments = flexmock(stats=False, list_archives=False)
|
|
|
module.prune_archives(
|
|
|
repository_path='repo',
|
|
|
storage_config={},
|
|
@@ -142,6 +145,7 @@ def test_prune_archives_with_log_info_calls_borg_with_info_flag():
|
|
|
retention_config=flexmock(),
|
|
|
local_borg_version='1.2.3',
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -153,6 +157,7 @@ def test_prune_archives_with_log_debug_calls_borg_with_debug_flag():
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--debug', '--show-rc', 'repo'), logging.INFO)
|
|
|
insert_logging_mock(logging.DEBUG)
|
|
|
|
|
|
+ prune_arguments = flexmock(stats=False, list_archives=False)
|
|
|
module.prune_archives(
|
|
|
repository_path='repo',
|
|
|
storage_config={},
|
|
@@ -160,6 +165,7 @@ def test_prune_archives_with_log_debug_calls_borg_with_debug_flag():
|
|
|
retention_config=flexmock(),
|
|
|
local_borg_version='1.2.3',
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -170,6 +176,7 @@ def test_prune_archives_with_dry_run_calls_borg_with_dry_run_flag():
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo'), logging.INFO)
|
|
|
|
|
|
+ prune_arguments = flexmock(stats=False, list_archives=False)
|
|
|
module.prune_archives(
|
|
|
repository_path='repo',
|
|
|
storage_config={},
|
|
@@ -177,6 +184,7 @@ def test_prune_archives_with_dry_run_calls_borg_with_dry_run_flag():
|
|
|
retention_config=flexmock(),
|
|
|
local_borg_version='1.2.3',
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -187,6 +195,7 @@ def test_prune_archives_with_local_path_calls_borg_via_local_path():
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:] + ('repo',), logging.INFO)
|
|
|
|
|
|
+ prune_arguments = flexmock(stats=False, list_archives=False)
|
|
|
module.prune_archives(
|
|
|
dry_run=False,
|
|
|
repository_path='repo',
|
|
@@ -195,6 +204,7 @@ def test_prune_archives_with_local_path_calls_borg_via_local_path():
|
|
|
local_borg_version='1.2.3',
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
local_path='borg1',
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -205,6 +215,7 @@ def test_prune_archives_with_remote_path_calls_borg_with_remote_path_flags():
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1', 'repo'), logging.INFO)
|
|
|
|
|
|
+ prune_arguments = flexmock(stats=False, list_archives=False)
|
|
|
module.prune_archives(
|
|
|
dry_run=False,
|
|
|
repository_path='repo',
|
|
@@ -213,6 +224,7 @@ def test_prune_archives_with_remote_path_calls_borg_with_remote_path_flags():
|
|
|
local_borg_version='1.2.3',
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
remote_path='borg1',
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -223,6 +235,7 @@ def test_prune_archives_with_stats_calls_borg_with_stats_flag_and_answer_output_
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), module.borgmatic.logger.ANSWER)
|
|
|
|
|
|
+ prune_arguments = flexmock(stats=True, list_archives=False)
|
|
|
module.prune_archives(
|
|
|
dry_run=False,
|
|
|
repository_path='repo',
|
|
@@ -230,7 +243,7 @@ def test_prune_archives_with_stats_calls_borg_with_stats_flag_and_answer_output_
|
|
|
retention_config=flexmock(),
|
|
|
local_borg_version='1.2.3',
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
- stats=True,
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -241,6 +254,7 @@ def test_prune_archives_with_files_calls_borg_with_list_flag_and_answer_output_l
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--list', 'repo'), module.borgmatic.logger.ANSWER)
|
|
|
|
|
|
+ prune_arguments = flexmock(stats=False, list_archives=True)
|
|
|
module.prune_archives(
|
|
|
dry_run=False,
|
|
|
repository_path='repo',
|
|
@@ -248,7 +262,7 @@ def test_prune_archives_with_files_calls_borg_with_list_flag_and_answer_output_l
|
|
|
retention_config=flexmock(),
|
|
|
local_borg_version='1.2.3',
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
- list_archives=True,
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -260,6 +274,7 @@ def test_prune_archives_with_umask_calls_borg_with_umask_flags():
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077', 'repo'), logging.INFO)
|
|
|
|
|
|
+ prune_arguments = flexmock(stats=False, list_archives=False)
|
|
|
module.prune_archives(
|
|
|
dry_run=False,
|
|
|
repository_path='repo',
|
|
@@ -267,6 +282,7 @@ def test_prune_archives_with_umask_calls_borg_with_umask_flags():
|
|
|
retention_config=flexmock(),
|
|
|
local_borg_version='1.2.3',
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -277,6 +293,7 @@ def test_prune_archives_with_log_json_calls_borg_with_log_json_flag():
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--log-json', 'repo'), logging.INFO)
|
|
|
|
|
|
+ prune_arguments = flexmock(stats=False, list_archives=False)
|
|
|
module.prune_archives(
|
|
|
dry_run=False,
|
|
|
repository_path='repo',
|
|
@@ -284,6 +301,7 @@ def test_prune_archives_with_log_json_calls_borg_with_log_json_flag():
|
|
|
retention_config=flexmock(),
|
|
|
local_borg_version='1.2.3',
|
|
|
global_arguments=flexmock(log_json=True),
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -295,6 +313,7 @@ def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5', 'repo'), logging.INFO)
|
|
|
|
|
|
+ prune_arguments = flexmock(stats=False, list_archives=False)
|
|
|
module.prune_archives(
|
|
|
dry_run=False,
|
|
|
repository_path='repo',
|
|
@@ -302,6 +321,7 @@ def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
|
|
|
retention_config=flexmock(),
|
|
|
local_borg_version='1.2.3',
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -312,6 +332,7 @@ def test_prune_archives_with_extra_borg_options_calls_borg_with_extra_options():
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--extra', '--options', 'repo'), logging.INFO)
|
|
|
|
|
|
+ prune_arguments = flexmock(stats=False, list_archives=False)
|
|
|
module.prune_archives(
|
|
|
dry_run=False,
|
|
|
repository_path='repo',
|
|
@@ -319,4 +340,69 @@ def test_prune_archives_with_extra_borg_options_calls_borg_with_extra_options():
|
|
|
retention_config=flexmock(),
|
|
|
local_borg_version='1.2.3',
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def test_prune_archives_with_date_based_matching_calls_borg_with_date_based_flags():
|
|
|
+ flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
+ flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
|
|
+ flexmock(module.flags).should_receive('make_flags').and_return(())
|
|
|
+ flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
|
|
+ flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
+ flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
|
|
|
+ (
|
|
|
+ '--newer',
|
|
|
+ '1d',
|
|
|
+ '--newest',
|
|
|
+ '1y',
|
|
|
+ '--older',
|
|
|
+ '1m',
|
|
|
+ '--oldest',
|
|
|
+ '1w',
|
|
|
+ '--match-archives',
|
|
|
+ None,
|
|
|
+ )
|
|
|
+ )
|
|
|
+ flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
|
|
+ flexmock(module.environment).should_receive('make_environment')
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ (
|
|
|
+ 'borg',
|
|
|
+ 'prune',
|
|
|
+ '--keep-daily',
|
|
|
+ '1',
|
|
|
+ '--keep-weekly',
|
|
|
+ '2',
|
|
|
+ '--keep-monthly',
|
|
|
+ '3',
|
|
|
+ '--newer',
|
|
|
+ '1d',
|
|
|
+ '--newest',
|
|
|
+ '1y',
|
|
|
+ '--older',
|
|
|
+ '1m',
|
|
|
+ '--oldest',
|
|
|
+ '1w',
|
|
|
+ '--match-archives',
|
|
|
+ None,
|
|
|
+ '--repo',
|
|
|
+ 'repo',
|
|
|
+ ),
|
|
|
+ output_log_level=logging.INFO,
|
|
|
+ borg_local_path='borg',
|
|
|
+ extra_environment=None,
|
|
|
+ )
|
|
|
+
|
|
|
+ prune_arguments = flexmock(
|
|
|
+ stats=False, list_archives=False, newer='1d', newest='1y', older='1m', oldest='1w'
|
|
|
+ )
|
|
|
+ module.prune_archives(
|
|
|
+ dry_run=False,
|
|
|
+ repository_path='repo',
|
|
|
+ storage_config={},
|
|
|
+ retention_config=flexmock(),
|
|
|
+ local_borg_version='1.2.3',
|
|
|
+ global_arguments=flexmock(log_json=False),
|
|
|
+ prune_arguments=prune_arguments,
|
|
|
)
|