diff --git a/tests/unit/actions/test_rcreate.py b/tests/unit/actions/test_rcreate.py index 8f07a8024..78d4af1f7 100644 --- a/tests/unit/actions/test_rcreate.py +++ b/tests/unit/actions/test_rcreate.py @@ -5,10 +5,39 @@ from borgmatic.actions import rcreate as module def test_run_rcreate_does_not_raise(): flexmock(module.logger).answer = lambda message: None + flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True) flexmock(module.borgmatic.borg.rcreate).should_receive('create_repository') arguments = flexmock( encryption_mode=flexmock(), source_repository=flexmock(), + repository=flexmock(), + copy_crypt_key=flexmock(), + append_only=flexmock(), + storage_quota=flexmock(), + make_parent_dirs=flexmock(), + ) + + module.run_rcreate( + repository='repo', + storage={}, + local_borg_version=None, + rcreate_arguments=arguments, + global_arguments=flexmock(dry_run=False), + local_path=None, + remote_path=None, + ) + + +def test_run_rcreate_bails_if_repository_does_not_match(): + flexmock(module.logger).answer = lambda message: None + flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return( + False + ) + flexmock(module.borgmatic.borg.rcreate).should_receive('create_repository').never() + arguments = flexmock( + encryption_mode=flexmock(), + source_repository=flexmock(), + repository=flexmock(), copy_crypt_key=flexmock(), append_only=flexmock(), storage_quota=flexmock(), diff --git a/tests/unit/borg/test_transfer.py b/tests/unit/borg/test_transfer.py index b7fef3c18..27b034705 100644 --- a/tests/unit/borg/test_transfer.py +++ b/tests/unit/borg/test_transfer.py @@ -18,6 +18,7 @@ def test_transfer_archives_calls_borg_with_flags(): flexmock(module).should_receive('execute_command').with_args( ('borg', 'transfer', '--repo', 'repo'), output_log_level=module.borgmatic.logger.ANSWER, + output_file=None, borg_local_path='borg', extra_environment=None, ) @@ -27,7 +28,9 @@ def test_transfer_archives_calls_borg_with_flags(): repository='repo', storage_config={}, local_borg_version='2.3.4', - transfer_arguments=flexmock(archive=None, match_archives=None, source_repository=None), + transfer_arguments=flexmock( + archive=None, progress=None, match_archives=None, source_repository=None + ), ) @@ -44,6 +47,7 @@ def test_transfer_archives_with_dry_run_calls_borg_with_dry_run_flag(): flexmock(module).should_receive('execute_command').with_args( ('borg', 'transfer', '--repo', 'repo', '--dry-run'), output_log_level=module.borgmatic.logger.ANSWER, + output_file=None, borg_local_path='borg', extra_environment=None, ) @@ -53,7 +57,9 @@ def test_transfer_archives_with_dry_run_calls_borg_with_dry_run_flag(): repository='repo', storage_config={}, local_borg_version='2.3.4', - transfer_arguments=flexmock(archive=None, match_archives=None, source_repository=None), + transfer_arguments=flexmock( + archive=None, progress=None, match_archives=None, source_repository=None + ), ) @@ -67,6 +73,7 @@ def test_transfer_archives_with_log_info_calls_borg_with_info_flag(): flexmock(module).should_receive('execute_command').with_args( ('borg', 'transfer', '--info', '--repo', 'repo'), output_log_level=module.borgmatic.logger.ANSWER, + output_file=None, borg_local_path='borg', extra_environment=None, ) @@ -76,7 +83,9 @@ def test_transfer_archives_with_log_info_calls_borg_with_info_flag(): repository='repo', storage_config={}, local_borg_version='2.3.4', - transfer_arguments=flexmock(archive=None, match_archives=None, source_repository=None), + transfer_arguments=flexmock( + archive=None, progress=None, match_archives=None, source_repository=None + ), ) @@ -90,6 +99,7 @@ def test_transfer_archives_with_log_debug_calls_borg_with_debug_flag(): flexmock(module).should_receive('execute_command').with_args( ('borg', 'transfer', '--debug', '--show-rc', '--repo', 'repo'), output_log_level=module.borgmatic.logger.ANSWER, + output_file=None, borg_local_path='borg', extra_environment=None, ) @@ -100,7 +110,9 @@ def test_transfer_archives_with_log_debug_calls_borg_with_debug_flag(): repository='repo', storage_config={}, local_borg_version='2.3.4', - transfer_arguments=flexmock(archive=None, match_archives=None, source_repository=None), + transfer_arguments=flexmock( + archive=None, progress=None, match_archives=None, source_repository=None + ), ) @@ -117,6 +129,7 @@ def test_transfer_archives_with_archive_calls_borg_with_match_archives_flag(): flexmock(module).should_receive('execute_command').with_args( ('borg', 'transfer', '--match-archives', 'archive', '--repo', 'repo'), output_log_level=module.borgmatic.logger.ANSWER, + output_file=None, borg_local_path='borg', extra_environment=None, ) @@ -126,7 +139,9 @@ def test_transfer_archives_with_archive_calls_borg_with_match_archives_flag(): repository='repo', storage_config={}, local_borg_version='2.3.4', - transfer_arguments=flexmock(archive='archive', match_archives=None, source_repository=None), + transfer_arguments=flexmock( + archive='archive', progress=None, match_archives=None, source_repository=None + ), ) @@ -143,6 +158,7 @@ def test_transfer_archives_with_match_archives_calls_borg_with_match_archives_fl flexmock(module).should_receive('execute_command').with_args( ('borg', 'transfer', '--match-archives', 'sh:foo*', '--repo', 'repo'), output_log_level=module.borgmatic.logger.ANSWER, + output_file=None, borg_local_path='borg', extra_environment=None, ) @@ -152,7 +168,9 @@ def test_transfer_archives_with_match_archives_calls_borg_with_match_archives_fl repository='repo', storage_config={}, local_borg_version='2.3.4', - transfer_arguments=flexmock(archive=None, match_archives='sh:foo*', source_repository=None), + transfer_arguments=flexmock( + archive=None, progress=None, match_archives='sh:foo*', source_repository=None + ), ) @@ -166,6 +184,7 @@ def test_transfer_archives_with_local_path_calls_borg_via_local_path(): flexmock(module).should_receive('execute_command').with_args( ('borg2', 'transfer', '--repo', 'repo'), output_log_level=module.borgmatic.logger.ANSWER, + output_file=None, borg_local_path='borg2', extra_environment=None, ) @@ -175,7 +194,9 @@ def test_transfer_archives_with_local_path_calls_borg_via_local_path(): repository='repo', storage_config={}, local_borg_version='2.3.4', - transfer_arguments=flexmock(archive=None, match_archives=None, source_repository=None), + transfer_arguments=flexmock( + archive=None, progress=None, match_archives=None, source_repository=None + ), local_path='borg2', ) @@ -193,6 +214,7 @@ def test_transfer_archives_with_remote_path_calls_borg_with_remote_path_flags(): flexmock(module).should_receive('execute_command').with_args( ('borg', 'transfer', '--remote-path', 'borg2', '--repo', 'repo'), output_log_level=module.borgmatic.logger.ANSWER, + output_file=None, borg_local_path='borg', extra_environment=None, ) @@ -202,7 +224,9 @@ def test_transfer_archives_with_remote_path_calls_borg_with_remote_path_flags(): repository='repo', storage_config={}, local_borg_version='2.3.4', - transfer_arguments=flexmock(archive=None, match_archives=None, source_repository=None), + transfer_arguments=flexmock( + archive=None, progress=None, match_archives=None, source_repository=None + ), remote_path='borg2', ) @@ -221,6 +245,7 @@ def test_transfer_archives_with_lock_wait_calls_borg_with_lock_wait_flags(): flexmock(module).should_receive('execute_command').with_args( ('borg', 'transfer', '--lock-wait', '5', '--repo', 'repo'), output_log_level=module.borgmatic.logger.ANSWER, + output_file=None, borg_local_path='borg', extra_environment=None, ) @@ -230,7 +255,35 @@ def test_transfer_archives_with_lock_wait_calls_borg_with_lock_wait_flags(): repository='repo', storage_config=storage_config, local_borg_version='2.3.4', - transfer_arguments=flexmock(archive=None, match_archives=None, source_repository=None), + transfer_arguments=flexmock( + archive=None, progress=None, match_archives=None, source_repository=None + ), + ) + + +def test_transfer_archives_with_progress_calls_borg_with_progress_flag(): + 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_flags_from_arguments').and_return(()) + 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', 'transfer', '--progress', '--repo', 'repo'), + output_log_level=module.borgmatic.logger.ANSWER, + output_file=module.DO_NOT_CAPTURE, + borg_local_path='borg', + extra_environment=None, + ) + + module.transfer_archives( + dry_run=False, + repository='repo', + storage_config={}, + local_borg_version='2.3.4', + transfer_arguments=flexmock( + archive=None, progress=True, match_archives=None, source_repository=None + ), ) @@ -248,6 +301,7 @@ def test_transfer_archives_passes_through_arguments_to_borg(argument_name): flexmock(module).should_receive('execute_command').with_args( ('borg', 'transfer', flag_name, 'value', '--repo', 'repo'), output_log_level=module.borgmatic.logger.ANSWER, + output_file=None, borg_local_path='borg', extra_environment=None, ) @@ -258,7 +312,11 @@ def test_transfer_archives_passes_through_arguments_to_borg(argument_name): storage_config={}, local_borg_version='2.3.4', transfer_arguments=flexmock( - archive=None, match_archives=None, source_repository=None, **{argument_name: 'value'} + archive=None, + progress=None, + match_archives=None, + source_repository=None, + **{argument_name: 'value'}, ), ) @@ -275,6 +333,7 @@ def test_transfer_archives_with_source_repository_calls_borg_with_other_repo_fla flexmock(module).should_receive('execute_command').with_args( ('borg', 'transfer', '--repo', 'repo', '--other-repo', 'other'), output_log_level=module.borgmatic.logger.ANSWER, + output_file=None, borg_local_path='borg', extra_environment=None, ) @@ -284,5 +343,7 @@ def test_transfer_archives_with_source_repository_calls_borg_with_other_repo_fla repository='repo', storage_config={}, local_borg_version='2.3.4', - transfer_arguments=flexmock(archive=None, match_archives=None, source_repository='other'), + transfer_arguments=flexmock( + archive=None, progress=None, match_archives=None, source_repository='other' + ), )