|
@@ -1,5 +1,4 @@
|
|
import logging
|
|
import logging
|
|
-import sys
|
|
|
|
|
|
|
|
from flexmock import flexmock
|
|
from flexmock import flexmock
|
|
|
|
|
|
@@ -8,61 +7,46 @@ from borgmatic.borg import extract as module
|
|
from ..test_verbosity import insert_logging_mock
|
|
from ..test_verbosity import insert_logging_mock
|
|
|
|
|
|
|
|
|
|
-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 insert_execute_command_mock(command):
|
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(command).once()
|
|
|
|
|
|
|
|
|
|
-def insert_subprocess_never():
|
|
|
|
- subprocess = flexmock(module.subprocess)
|
|
|
|
- subprocess.should_receive('check_call').never()
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def insert_subprocess_check_output_mock(check_output_command, result, **kwargs):
|
|
|
|
- subprocess = flexmock(module.subprocess)
|
|
|
|
- subprocess.should_receive('check_output').with_args(check_output_command, **kwargs).and_return(
|
|
|
|
- result
|
|
|
|
- ).once()
|
|
|
|
|
|
+def insert_execute_command_output_mock(command, result):
|
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
+ command, output_log_level=None
|
|
|
|
+ ).and_return(result).once()
|
|
|
|
|
|
|
|
|
|
def test_extract_last_archive_dry_run_calls_borg_with_last_archive():
|
|
def test_extract_last_archive_dry_run_calls_borg_with_last_archive():
|
|
- flexmock(sys.stdout).encoding = 'utf-8'
|
|
|
|
- insert_subprocess_check_output_mock(
|
|
|
|
- ('borg', 'list', '--short', 'repo'), result='archive1\narchive2\n'.encode('utf-8')
|
|
|
|
|
|
+ insert_execute_command_output_mock(
|
|
|
|
+ ('borg', 'list', '--short', 'repo'), result='archive1\narchive2\n'
|
|
)
|
|
)
|
|
- insert_subprocess_mock(('borg', 'extract', '--dry-run', 'repo::archive2'))
|
|
|
|
|
|
+ insert_execute_command_mock(('borg', 'extract', '--dry-run', 'repo::archive2'))
|
|
|
|
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None)
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None)
|
|
|
|
|
|
|
|
|
|
-def test_extract_last_archive_dry_run_without_any_archives_should_bail():
|
|
|
|
- flexmock(sys.stdout).encoding = 'utf-8'
|
|
|
|
- insert_subprocess_check_output_mock(
|
|
|
|
- ('borg', 'list', '--short', 'repo'), result='\n'.encode('utf-8')
|
|
|
|
- )
|
|
|
|
- insert_subprocess_never()
|
|
|
|
|
|
+def test_extract_last_archive_dry_run_without_any_archives_should_not_raise():
|
|
|
|
+ insert_execute_command_output_mock(('borg', 'list', '--short', 'repo'), result='\n')
|
|
|
|
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None)
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None)
|
|
|
|
|
|
|
|
|
|
def test_extract_last_archive_dry_run_with_log_info_calls_borg_with_info_parameter():
|
|
def test_extract_last_archive_dry_run_with_log_info_calls_borg_with_info_parameter():
|
|
- flexmock(sys.stdout).encoding = 'utf-8'
|
|
|
|
- insert_subprocess_check_output_mock(
|
|
|
|
- ('borg', 'list', '--short', 'repo', '--info'), result='archive1\narchive2\n'.encode('utf-8')
|
|
|
|
|
|
+ insert_execute_command_output_mock(
|
|
|
|
+ ('borg', 'list', '--short', 'repo', '--info'), result='archive1\narchive2\n'
|
|
)
|
|
)
|
|
- insert_subprocess_mock(('borg', 'extract', '--dry-run', 'repo::archive2', '--info'))
|
|
|
|
|
|
+ insert_execute_command_mock(('borg', 'extract', '--dry-run', 'repo::archive2', '--info'))
|
|
insert_logging_mock(logging.INFO)
|
|
insert_logging_mock(logging.INFO)
|
|
|
|
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None)
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None)
|
|
|
|
|
|
|
|
|
|
def test_extract_last_archive_dry_run_with_log_debug_calls_borg_with_debug_parameter():
|
|
def test_extract_last_archive_dry_run_with_log_debug_calls_borg_with_debug_parameter():
|
|
- flexmock(sys.stdout).encoding = 'utf-8'
|
|
|
|
- insert_subprocess_check_output_mock(
|
|
|
|
- ('borg', 'list', '--short', 'repo', '--debug', '--show-rc'),
|
|
|
|
- result='archive1\narchive2\n'.encode('utf-8'),
|
|
|
|
|
|
+ insert_execute_command_output_mock(
|
|
|
|
+ ('borg', 'list', '--short', 'repo', '--debug', '--show-rc'), result='archive1\narchive2\n'
|
|
)
|
|
)
|
|
- insert_subprocess_mock(
|
|
|
|
|
|
+ insert_execute_command_mock(
|
|
('borg', 'extract', '--dry-run', 'repo::archive2', '--debug', '--show-rc', '--list')
|
|
('borg', 'extract', '--dry-run', 'repo::archive2', '--debug', '--show-rc', '--list')
|
|
)
|
|
)
|
|
insert_logging_mock(logging.DEBUG)
|
|
insert_logging_mock(logging.DEBUG)
|
|
@@ -71,22 +55,19 @@ def test_extract_last_archive_dry_run_with_log_debug_calls_borg_with_debug_param
|
|
|
|
|
|
|
|
|
|
def test_extract_last_archive_dry_run_calls_borg_via_local_path():
|
|
def test_extract_last_archive_dry_run_calls_borg_via_local_path():
|
|
- flexmock(sys.stdout).encoding = 'utf-8'
|
|
|
|
- insert_subprocess_check_output_mock(
|
|
|
|
- ('borg1', 'list', '--short', 'repo'), result='archive1\narchive2\n'.encode('utf-8')
|
|
|
|
|
|
+ insert_execute_command_output_mock(
|
|
|
|
+ ('borg1', 'list', '--short', 'repo'), result='archive1\narchive2\n'
|
|
)
|
|
)
|
|
- insert_subprocess_mock(('borg1', 'extract', '--dry-run', 'repo::archive2'))
|
|
|
|
|
|
+ insert_execute_command_mock(('borg1', 'extract', '--dry-run', 'repo::archive2'))
|
|
|
|
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None, local_path='borg1')
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None, local_path='borg1')
|
|
|
|
|
|
|
|
|
|
def test_extract_last_archive_dry_run_calls_borg_with_remote_path_parameters():
|
|
def test_extract_last_archive_dry_run_calls_borg_with_remote_path_parameters():
|
|
- flexmock(sys.stdout).encoding = 'utf-8'
|
|
|
|
- insert_subprocess_check_output_mock(
|
|
|
|
- ('borg', 'list', '--short', 'repo', '--remote-path', 'borg1'),
|
|
|
|
- result='archive1\narchive2\n'.encode('utf-8'),
|
|
|
|
|
|
+ insert_execute_command_output_mock(
|
|
|
|
+ ('borg', 'list', '--short', 'repo', '--remote-path', 'borg1'), result='archive1\narchive2\n'
|
|
)
|
|
)
|
|
- insert_subprocess_mock(
|
|
|
|
|
|
+ insert_execute_command_mock(
|
|
('borg', 'extract', '--dry-run', 'repo::archive2', '--remote-path', 'borg1')
|
|
('borg', 'extract', '--dry-run', 'repo::archive2', '--remote-path', 'borg1')
|
|
)
|
|
)
|
|
|
|
|
|
@@ -94,18 +75,18 @@ def test_extract_last_archive_dry_run_calls_borg_with_remote_path_parameters():
|
|
|
|
|
|
|
|
|
|
def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_parameters():
|
|
def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_parameters():
|
|
- flexmock(sys.stdout).encoding = 'utf-8'
|
|
|
|
- insert_subprocess_check_output_mock(
|
|
|
|
- ('borg', 'list', '--short', 'repo', '--lock-wait', '5'),
|
|
|
|
- result='archive1\narchive2\n'.encode('utf-8'),
|
|
|
|
|
|
+ insert_execute_command_output_mock(
|
|
|
|
+ ('borg', 'list', '--short', 'repo', '--lock-wait', '5'), result='archive1\narchive2\n'
|
|
|
|
+ )
|
|
|
|
+ insert_execute_command_mock(
|
|
|
|
+ ('borg', 'extract', '--dry-run', 'repo::archive2', '--lock-wait', '5')
|
|
)
|
|
)
|
|
- insert_subprocess_mock(('borg', 'extract', '--dry-run', 'repo::archive2', '--lock-wait', '5'))
|
|
|
|
|
|
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=5)
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=5)
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_calls_borg_with_restore_path_parameters():
|
|
def test_extract_archive_calls_borg_with_restore_path_parameters():
|
|
- insert_subprocess_mock(('borg', 'extract', 'repo::archive', 'path1', 'path2'))
|
|
|
|
|
|
+ insert_execute_command_mock(('borg', 'extract', 'repo::archive', 'path1', 'path2'))
|
|
|
|
|
|
module.extract_archive(
|
|
module.extract_archive(
|
|
dry_run=False,
|
|
dry_run=False,
|
|
@@ -118,7 +99,7 @@ def test_extract_archive_calls_borg_with_restore_path_parameters():
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_calls_borg_with_remote_path_parameters():
|
|
def test_extract_archive_calls_borg_with_remote_path_parameters():
|
|
- insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--remote-path', 'borg1'))
|
|
|
|
|
|
+ insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--remote-path', 'borg1'))
|
|
|
|
|
|
module.extract_archive(
|
|
module.extract_archive(
|
|
dry_run=False,
|
|
dry_run=False,
|
|
@@ -132,7 +113,7 @@ def test_extract_archive_calls_borg_with_remote_path_parameters():
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_calls_borg_with_numeric_owner_parameter():
|
|
def test_extract_archive_calls_borg_with_numeric_owner_parameter():
|
|
- insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--numeric-owner'))
|
|
|
|
|
|
+ insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--numeric-owner'))
|
|
|
|
|
|
module.extract_archive(
|
|
module.extract_archive(
|
|
dry_run=False,
|
|
dry_run=False,
|
|
@@ -145,7 +126,7 @@ def test_extract_archive_calls_borg_with_numeric_owner_parameter():
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_calls_borg_with_umask_parameters():
|
|
def test_extract_archive_calls_borg_with_umask_parameters():
|
|
- insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--umask', '0770'))
|
|
|
|
|
|
+ insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--umask', '0770'))
|
|
|
|
|
|
module.extract_archive(
|
|
module.extract_archive(
|
|
dry_run=False,
|
|
dry_run=False,
|
|
@@ -158,7 +139,7 @@ def test_extract_archive_calls_borg_with_umask_parameters():
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_calls_borg_with_lock_wait_parameters():
|
|
def test_extract_archive_calls_borg_with_lock_wait_parameters():
|
|
- insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--lock-wait', '5'))
|
|
|
|
|
|
+ insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--lock-wait', '5'))
|
|
|
|
|
|
module.extract_archive(
|
|
module.extract_archive(
|
|
dry_run=False,
|
|
dry_run=False,
|
|
@@ -171,7 +152,7 @@ def test_extract_archive_calls_borg_with_lock_wait_parameters():
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
|
|
def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
|
|
- insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--info'))
|
|
|
|
|
|
+ insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--info'))
|
|
insert_logging_mock(logging.INFO)
|
|
insert_logging_mock(logging.INFO)
|
|
|
|
|
|
module.extract_archive(
|
|
module.extract_archive(
|
|
@@ -185,7 +166,9 @@ def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters():
|
|
def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters():
|
|
- insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--debug', '--list', '--show-rc'))
|
|
|
|
|
|
+ insert_execute_command_mock(
|
|
|
|
+ ('borg', 'extract', 'repo::archive', '--debug', '--list', '--show-rc')
|
|
|
|
+ )
|
|
insert_logging_mock(logging.DEBUG)
|
|
insert_logging_mock(logging.DEBUG)
|
|
|
|
|
|
module.extract_archive(
|
|
module.extract_archive(
|
|
@@ -199,7 +182,7 @@ def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters():
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_calls_borg_with_dry_run_parameter():
|
|
def test_extract_archive_calls_borg_with_dry_run_parameter():
|
|
- insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--dry-run'))
|
|
|
|
|
|
+ insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--dry-run'))
|
|
|
|
|
|
module.extract_archive(
|
|
module.extract_archive(
|
|
dry_run=True,
|
|
dry_run=True,
|
|
@@ -212,7 +195,7 @@ def test_extract_archive_calls_borg_with_dry_run_parameter():
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_calls_borg_with_progress_parameter():
|
|
def test_extract_archive_calls_borg_with_progress_parameter():
|
|
- insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--progress'))
|
|
|
|
|
|
+ insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--progress'))
|
|
|
|
|
|
module.extract_archive(
|
|
module.extract_archive(
|
|
dry_run=False,
|
|
dry_run=False,
|