From 8aaba9bb0ade4f765c42206e076c36dcb56f245e Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 24 Apr 2023 20:43:34 +0530 Subject: [PATCH] Added new flags to prune test for review Signed-off-by: Chirag Aggarwal --- tests/unit/borg/test_prune.py | 41 ++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/tests/unit/borg/test_prune.py b/tests/unit/borg/test_prune.py index 2ed9c90..66cb7cd 100644 --- a/tests/unit/borg/test_prune.py +++ b/tests/unit/borg/test_prune.py @@ -166,23 +166,6 @@ def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter(): ) -# def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter(): -# flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels') -# flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER -# flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS) -# 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={}, -# dry_run=True, -# retention_config=flexmock(), -# local_borg_version='1.2.3', -# prune_arguments=prune_arguments, -# ) - def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter(): flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels') flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER @@ -329,3 +312,27 @@ def test_prune_archives_with_extra_borg_options_calls_borg_with_extra_options(): local_borg_version='1.2.3', 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).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS) + flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) + insert_execute_command_mock( + PRUNE_COMMAND + + ('--newer', '1d', '--newest', '1y', '--older', '1m', '--oldest', '1w', 'repo'), + logging.INFO, + ) + + 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', + prune_arguments=prune_arguments, + )