123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746 |
- import logging
- import pytest
- from flexmock import flexmock
- from borgmatic.borg import extract as module
- from ..test_verbosity import insert_logging_mock
- def insert_execute_command_mock(command, destination_path=None, borg_exit_codes=None):
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- command,
- extra_environment=None,
- working_directory=destination_path,
- borg_local_path=command[0],
- borg_exit_codes=borg_exit_codes,
- ).once()
- def test_extract_last_archive_dry_run_calls_borg_with_last_archive():
- flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
- insert_execute_command_mock(('borg', 'extract', '--dry-run', 'repo::archive'))
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- module.extract_last_archive_dry_run(
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- repository_path='repo',
- lock_wait=None,
- )
- def test_extract_last_archive_dry_run_without_any_archives_should_not_raise():
- flexmock(module.repo_list).should_receive('resolve_archive_name').and_raise(ValueError)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(('repo',))
- module.extract_last_archive_dry_run(
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- repository_path='repo',
- lock_wait=None,
- )
- def test_extract_last_archive_dry_run_with_log_info_calls_borg_with_info_parameter():
- flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
- insert_execute_command_mock(('borg', 'extract', '--dry-run', '--info', 'repo::archive'))
- insert_logging_mock(logging.INFO)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- module.extract_last_archive_dry_run(
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- repository_path='repo',
- lock_wait=None,
- )
- def test_extract_last_archive_dry_run_with_log_debug_calls_borg_with_debug_parameter():
- flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
- insert_execute_command_mock(
- ('borg', 'extract', '--dry-run', '--debug', '--show-rc', '--list', 'repo::archive')
- )
- insert_logging_mock(logging.DEBUG)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- module.extract_last_archive_dry_run(
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- repository_path='repo',
- lock_wait=None,
- )
- def test_extract_last_archive_dry_run_calls_borg_via_local_path():
- flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
- insert_execute_command_mock(('borg1', 'extract', '--dry-run', 'repo::archive'))
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- module.extract_last_archive_dry_run(
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- repository_path='repo',
- lock_wait=None,
- local_path='borg1',
- )
- def test_extract_last_archive_dry_run_calls_borg_using_exit_codes():
- flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
- borg_exit_codes = flexmock()
- insert_execute_command_mock(
- ('borg', 'extract', '--dry-run', 'repo::archive'), borg_exit_codes=borg_exit_codes
- )
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- module.extract_last_archive_dry_run(
- config={'borg_exit_codes': borg_exit_codes},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- repository_path='repo',
- lock_wait=None,
- )
- def test_extract_last_archive_dry_run_calls_borg_with_remote_path_flags():
- flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
- insert_execute_command_mock(
- ('borg', 'extract', '--dry-run', '--remote-path', 'borg1', 'repo::archive')
- )
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- module.extract_last_archive_dry_run(
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- repository_path='repo',
- lock_wait=None,
- remote_path='borg1',
- )
- def test_extract_last_archive_dry_run_calls_borg_with_log_json_flag():
- flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
- insert_execute_command_mock(('borg', 'extract', '--dry-run', '--log-json', 'repo::archive'))
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- module.extract_last_archive_dry_run(
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=True),
- repository_path='repo',
- lock_wait=None,
- )
- def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_flags():
- flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
- insert_execute_command_mock(
- ('borg', 'extract', '--dry-run', '--lock-wait', '5', 'repo::archive')
- )
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- module.extract_last_archive_dry_run(
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- repository_path='repo',
- lock_wait=5,
- )
- def test_extract_archive_calls_borg_with_path_flags():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(('borg', 'extract', 'repo::archive', 'path1', 'path2'))
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=['path1', 'path2'],
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- )
- def test_extract_archive_calls_borg_with_local_path():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(('borg1', 'extract', 'repo::archive'))
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- local_path='borg1',
- )
- def test_extract_archive_calls_borg_with_exit_codes():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- borg_exit_codes = flexmock()
- insert_execute_command_mock(
- ('borg', 'extract', 'repo::archive'), borg_exit_codes=borg_exit_codes
- )
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={'borg_exit_codes': borg_exit_codes},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- )
- def test_extract_archive_calls_borg_with_remote_path_flags():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(('borg', 'extract', '--remote-path', 'borg1', 'repo::archive'))
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- remote_path='borg1',
- )
- @pytest.mark.parametrize(
- 'feature_available,option_flag',
- (
- (True, '--numeric-ids'),
- (False, '--numeric-owner'),
- ),
- )
- def test_extract_archive_calls_borg_with_numeric_ids_parameter(feature_available, option_flag):
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(('borg', 'extract', option_flag, 'repo::archive'))
- flexmock(module.feature).should_receive('available').and_return(feature_available)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={'numeric_ids': True},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- )
- def test_extract_archive_calls_borg_with_umask_flags():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(('borg', 'extract', '--umask', '0770', 'repo::archive'))
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={'umask': '0770'},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- )
- def test_extract_archive_calls_borg_with_log_json_flags():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(('borg', 'extract', '--log-json', 'repo::archive'))
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=True),
- )
- def test_extract_archive_calls_borg_with_lock_wait_flags():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(('borg', 'extract', '--lock-wait', '5', 'repo::archive'))
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={'lock_wait': '5'},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- )
- def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(('borg', 'extract', '--info', 'repo::archive'))
- insert_logging_mock(logging.INFO)
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- )
- def test_extract_archive_with_log_debug_calls_borg_with_debug_flags():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(
- ('borg', 'extract', '--debug', '--list', '--show-rc', 'repo::archive')
- )
- insert_logging_mock(logging.DEBUG)
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- )
- def test_extract_archive_calls_borg_with_dry_run_parameter():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(('borg', 'extract', '--dry-run', 'repo::archive'))
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=True,
- repository='repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- )
- def test_extract_archive_calls_borg_with_destination_path():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(('borg', 'extract', 'repo::archive'), destination_path='/dest')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- destination_path='/dest',
- )
- def test_extract_archive_calls_borg_with_strip_components():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(('borg', 'extract', '--strip-components', '5', 'repo::archive'))
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- strip_components=5,
- )
- def test_extract_archive_calls_borg_with_strip_components_calculated_from_all():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(
- (
- 'borg',
- 'extract',
- '--strip-components',
- '2',
- 'repo::archive',
- 'foo/bar/baz.txt',
- 'foo/bar.txt',
- )
- )
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=['foo/bar/baz.txt', 'foo/bar.txt'],
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- strip_components='all',
- )
- def test_extract_archive_calls_borg_with_strip_components_calculated_from_all_with_leading_slash():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(
- (
- 'borg',
- 'extract',
- '--strip-components',
- '2',
- 'repo::archive',
- '/foo/bar/baz.txt',
- '/foo/bar.txt',
- )
- )
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=['/foo/bar/baz.txt', '/foo/bar.txt'],
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- strip_components='all',
- )
- def test_extract_archive_with_strip_components_all_and_no_paths_raises():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- flexmock(module).should_receive('execute_command').never()
- with pytest.raises(ValueError):
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- strip_components='all',
- )
- def test_extract_archive_calls_borg_with_progress_parameter():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'extract', '--progress', 'repo::archive'),
- output_file=module.DO_NOT_CAPTURE,
- extra_environment=None,
- working_directory=None,
- borg_local_path='borg',
- borg_exit_codes=None,
- ).once()
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- progress=True,
- )
- def test_extract_archive_with_progress_and_extract_to_stdout_raises():
- flexmock(module).should_receive('execute_command').never()
- with pytest.raises(ValueError):
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- progress=True,
- extract_to_stdout=True,
- )
- def test_extract_archive_calls_borg_with_stdout_parameter_and_returns_process():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- process = flexmock()
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'extract', '--stdout', 'repo::archive'),
- output_file=module.subprocess.PIPE,
- run_to_completion=False,
- extra_environment=None,
- working_directory=None,
- borg_local_path='borg',
- borg_exit_codes=None,
- ).and_return(process).once()
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- assert (
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- extract_to_stdout=True,
- )
- == process
- )
- def test_extract_archive_skips_abspath_for_remote_repository():
- flexmock(module.os.path).should_receive('abspath').never()
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'extract', 'server:repo::archive'),
- extra_environment=None,
- working_directory=None,
- borg_local_path='borg',
- borg_exit_codes=None,
- ).once()
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('server:repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).and_return('repo')
- module.extract_archive(
- dry_run=False,
- repository='server:repo',
- archive='archive',
- paths=None,
- config={},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- )
- def test_extract_archive_uses_configured_working_directory_in_repo_path_and_destination_path():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(
- ('borg', 'extract', '/working/dir/repo::archive'), destination_path='/working/dir/dest'
- )
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('/working/dir/repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).with_args('/working/dir/repo').and_return('/working/dir/repo').once()
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={'working_directory': '/working/dir'},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- destination_path='dest',
- )
- def test_extract_archive_uses_configured_working_directory_in_repo_path_when_destination_path_is_not_set():
- flexmock(module.os.path).should_receive('abspath').and_return('repo')
- insert_execute_command_mock(('borg', 'extract', '/working/dir/repo::archive'))
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('/working/dir/repo::archive',)
- )
- flexmock(module.borgmatic.config.validate).should_receive(
- 'normalize_repository_path'
- ).with_args('/working/dir/repo').and_return('/working/dir/repo').once()
- module.extract_archive(
- dry_run=False,
- repository='repo',
- archive='archive',
- paths=None,
- config={'working_directory': '/working/dir'},
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False),
- )
|