|
@@ -69,11 +69,6 @@ def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
|
|
|
module._write_pattern_file([])
|
|
|
|
|
|
|
|
|
-def insert_subprocess_mock(check_call_command, **kwargs):
|
|
|
- subprocess = flexmock(module.subprocess)
|
|
|
- subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
|
|
|
-
|
|
|
-
|
|
|
def test_make_pattern_flags_includes_pattern_filename_when_given():
|
|
|
pattern_flags = module._make_pattern_flags(
|
|
|
location_config={'patterns': ['R /', '- /var']}, pattern_filename='/tmp/patterns'
|
|
@@ -169,7 +164,9 @@ def test_create_archive_calls_borg_with_parameters():
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND)
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND, capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -192,7 +189,9 @@ def test_create_archive_with_patterns_calls_borg_with_patterns():
|
|
|
).and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + pattern_flags)
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + pattern_flags, capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -215,7 +214,9 @@ def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
|
|
|
)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + exclude_flags)
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + exclude_flags, capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -236,7 +237,9 @@ def test_create_archive_with_log_info_calls_borg_with_info_parameter():
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME-', '--info', '--stats'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--list', '--filter', 'AME-', '--info', '--stats'), capture_output=False
|
|
|
+ )
|
|
|
insert_logging_mock(logging.INFO)
|
|
|
|
|
|
module.create_archive(
|
|
@@ -257,8 +260,9 @@ def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(
|
|
|
- CREATE_COMMAND + ('--list', '--filter', 'AME-', '--stats', '--debug', '--show-rc')
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--list', '--filter', 'AME-', '--stats', '--debug', '--show-rc'),
|
|
|
+ capture_output=False,
|
|
|
)
|
|
|
insert_logging_mock(logging.DEBUG)
|
|
|
|
|
@@ -281,7 +285,9 @@ def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--dry-run',))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--dry-run',), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=True,
|
|
@@ -304,7 +310,9 @@ def test_create_archive_with_dry_run_and_log_info_calls_borg_without_stats_param
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME-', '--info', '--dry-run'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--list', '--filter', 'AME-', '--info', '--dry-run'), capture_output=False
|
|
|
+ )
|
|
|
insert_logging_mock(logging.INFO)
|
|
|
|
|
|
module.create_archive(
|
|
@@ -328,8 +336,9 @@ def test_create_archive_with_dry_run_and_log_debug_calls_borg_without_stats_para
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(
|
|
|
- CREATE_COMMAND + ('--list', '--filter', 'AME-', '--debug', '--show-rc', '--dry-run')
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--list', '--filter', 'AME-', '--debug', '--show-rc', '--dry-run'),
|
|
|
+ capture_output=False,
|
|
|
)
|
|
|
insert_logging_mock(logging.DEBUG)
|
|
|
|
|
@@ -351,7 +360,9 @@ def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_inte
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--checkpoint-interval', '600'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--checkpoint-interval', '600'), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -371,7 +382,9 @@ def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_param
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--chunker-params', '1,2,3,4'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--chunker-params', '1,2,3,4'), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -391,7 +404,9 @@ def test_create_archive_with_compression_calls_borg_with_compression_parameters(
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--compression', 'rle'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--compression', 'rle'), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -411,7 +426,9 @@ def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--remote-ratelimit', '100'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--remote-ratelimit', '100'), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -431,7 +448,9 @@ def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_par
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--one-file-system',))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--one-file-system',), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -452,7 +471,9 @@ def test_create_archive_with_numeric_owner_calls_borg_with_numeric_owner_paramet
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--numeric-owner',))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--numeric-owner',), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -473,7 +494,9 @@ def test_create_archive_with_read_special_calls_borg_with_read_special_parameter
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--read-special',))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--read-special',), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -494,7 +517,9 @@ def test_create_archive_with_bsd_flags_true_calls_borg_without_nobsdflags_parame
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND)
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND, capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -515,7 +540,9 @@ def test_create_archive_with_bsd_flags_false_calls_borg_with_nobsdflags_paramete
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--nobsdflags',))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--nobsdflags',), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -536,7 +563,9 @@ def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters(
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--files-cache', 'ctime,size'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--files-cache', 'ctime,size'), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -557,7 +586,9 @@ def test_create_archive_with_local_path_calls_borg_via_local_path():
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(('borg1',) + CREATE_COMMAND[1:])
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ ('borg1',) + CREATE_COMMAND[1:], capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -578,7 +609,9 @@ def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters(
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--remote-path', 'borg1'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--remote-path', 'borg1'), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -599,7 +632,9 @@ def test_create_archive_with_umask_calls_borg_with_umask_parameters():
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--umask', '740'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--umask', '740'), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -619,7 +654,9 @@ def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--lock-wait', '5'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--lock-wait', '5'), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -639,9 +676,11 @@ def test_create_archive_with_json_calls_borg_with_json_parameter():
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(CREATE_COMMAND + ('--json',))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ CREATE_COMMAND + ('--json',), capture_output=True
|
|
|
+ ).and_return('[]')
|
|
|
|
|
|
- module.create_archive(
|
|
|
+ json_output = module.create_archive(
|
|
|
dry_run=False,
|
|
|
repository='repo',
|
|
|
location_config={
|
|
@@ -653,6 +692,8 @@ def test_create_archive_with_json_calls_borg_with_json_parameter():
|
|
|
json=True,
|
|
|
)
|
|
|
|
|
|
+ assert json_output == '[]'
|
|
|
+
|
|
|
|
|
|
def test_create_archive_with_source_directories_glob_expands():
|
|
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food'))
|
|
@@ -660,8 +701,9 @@ def test_create_archive_with_source_directories_glob_expands():
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(
|
|
|
- ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food')
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
|
|
|
+ capture_output=False,
|
|
|
)
|
|
|
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
|
|
|
|
|
@@ -683,7 +725,9 @@ def test_create_archive_with_non_matching_source_directories_glob_passes_through
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'), capture_output=False
|
|
|
+ )
|
|
|
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
|
|
|
|
|
|
module.create_archive(
|
|
@@ -704,8 +748,9 @@ def test_create_archive_with_glob_calls_borg_with_expanded_directories():
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(
|
|
|
- ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food')
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
|
|
|
+ capture_output=False,
|
|
|
)
|
|
|
|
|
|
module.create_archive(
|
|
@@ -726,7 +771,9 @@ def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ ('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|
|
@@ -746,7 +793,9 @@ def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
|
|
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
|
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
|
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
|
|
- insert_subprocess_mock(('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'))
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
+ ('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'), capture_output=False
|
|
|
+ )
|
|
|
|
|
|
module.create_archive(
|
|
|
dry_run=False,
|