This commit is contained in:
Divyansh Singh 2023-06-08 00:07:36 +05:30
parent dcb90bba50
commit 8384eaefb1
4 changed files with 51 additions and 6 deletions

View file

@ -24,9 +24,9 @@ def test_get_config_paths_returns_list_of_config_paths():
flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name').and_return( flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name').and_return(
'archive' 'archive'
) )
assert module.get_config_paths( assert module.get_config_paths(bootstrap_arguments, global_arguments, local_borg_version) == [
bootstrap_arguments, global_arguments, local_borg_version '/borgmatic/config.yaml'
) == ['/borgmatic/config.yaml'] ]
def test_run_bootstrap_does_not_raise(): def test_run_bootstrap_does_not_raise():

View file

@ -1,4 +1,5 @@
import sys import sys
from flexmock import flexmock from flexmock import flexmock
from borgmatic.actions import create as module from borgmatic.actions import create as module
@ -131,9 +132,7 @@ def test_create_borgmatic_manifest_creates_manifest_file_with_custom_borgmatic_s
'/borgmatic/bootstrap/manifest.json', 'w' '/borgmatic/bootstrap/manifest.json', 'w'
).and_return( ).and_return(
flexmock( flexmock(
__enter__=lambda *args: flexmock( __enter__=lambda *args: flexmock(write=lambda *args: None, close=lambda *args: None),
write=lambda *args: None, close=lambda *args: None
),
__exit__=lambda *args: None, __exit__=lambda *args: None,
) )
) )

View file

@ -586,6 +586,51 @@ def test_create_archive_with_patterns_calls_borg_with_patterns_including_convert
) )
def test_create_archive_with_sources_and_used_config_paths_calls_borg_with_sources_and_config_paths():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
flexmock(module).should_receive('deduplicate_directories').and_return(
('foo', 'bar', '/etc/borgmatic/config.yaml')
)
flexmock(module).should_receive('map_directories_to_devices').and_return({})
flexmock(module).should_receive('expand_directories').and_return(())
flexmock(module).should_receive('pattern_root_directories').and_return([])
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
flexmock(module).should_receive('expand_home_directories').and_return(())
flexmock(module).should_receive('write_pattern_file').and_return(None)
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
flexmock(module.feature).should_receive('available').and_return(True)
flexmock(module).should_receive('ensure_files_readable')
flexmock(module).should_receive('make_pattern_flags').and_return(())
flexmock(module).should_receive('make_exclude_flags').and_return(())
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
)
environment = {'BORG_THINGY': 'YUP'}
flexmock(module.environment).should_receive('make_environment').and_return(environment)
flexmock(module).should_receive('execute_command').with_args(
('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('/etc/borgmatic/config.yaml',),
output_log_level=logging.INFO,
output_file=None,
borg_local_path='borg',
working_directory=None,
extra_environment=environment,
)
module.create_archive(
dry_run=False,
repository_path='repo',
location_config={
'source_directories': ['foo', 'bar'],
'repositories': ['repo'],
},
storage_config={},
local_borg_version='1.2.3',
global_arguments=flexmock(log_json=False, used_config_paths=['/etc/borgmatic/config.yaml']),
)
def test_create_archive_with_exclude_patterns_calls_borg_with_excludes(): def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels') flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER

View file

@ -1002,6 +1002,7 @@ def test_collect_configuration_run_summary_logs_info_for_success_with_bootstrap(
) )
assert {log.levelno for log in logs} == {logging.INFO} assert {log.levelno for log in logs} == {logging.INFO}
def test_collect_configuration_run_summary_logs_error_on_bootstrap_failure(): def test_collect_configuration_run_summary_logs_error_on_bootstrap_failure():
flexmock(module.validate).should_receive('guard_single_repository_selected').never() flexmock(module.validate).should_receive('guard_single_repository_selected').never()
flexmock(module.validate).should_receive('guard_configuration_contains_repository').never() flexmock(module.validate).should_receive('guard_configuration_contains_repository').never()