Fix the (unreleased) "archive_hostname" option / "--archive-hostname" flag to pass an environment variable to Borg instead of a flag. Also add an "archive_username" option and corresponding "--archive-username" flag to override the "{user}" plaecholder (#1317).

This commit is contained in:
Dan Helfman
2026-07-20 18:57:11 -07:00
parent d454f3a3af
commit e428d74258
48 changed files with 13 additions and 704 deletions
-30
View File
@@ -188,36 +188,6 @@ def test_run_arbitrary_borg_with_exit_codes_calls_borg_using_them():
)
def test_run_arbitrary_borg_with_archive_hostname_calls_borg_with_hostname_flags():
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').with_args(
'hostname', 'example.org'
).and_return(
('--hostname', 'example.org'),
)
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', 'break-lock', '--hostname', 'example.org', '::'),
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
shell=True,
environment={'BORG_REPO': 'repo', 'ARCHIVE': ''},
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
)
insert_logging_mock(logging.WARNING)
module.run_arbitrary_borg(
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
options=['break-lock', '::'],
)
def test_run_arbitrary_borg_with_remote_path_calls_borg_with_remote_path_flags():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
-15
View File
@@ -62,21 +62,6 @@ def test_break_lock_calls_borg_using_exit_codes():
)
def test_break_lock_calls_borg_with_hostname_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
('borg', 'break-lock', '--hostname', 'example.org', '--log-json', 'repo')
)
insert_logging_mock(logging.WARNING)
module.break_lock(
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
def test_break_lock_calls_borg_with_remote_path_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
-18
View File
@@ -81,24 +81,6 @@ def test_change_passphrase_calls_borg_using_exit_codes():
)
def test_change_passphrase_calls_borg_with_hostname_flags():
config = {'archive_hostname': 'example.org'}
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
('borg', 'key', 'change-passphrase', '--hostname', 'example.org', 'repo'),
config=config,
)
insert_logging_mock(logging.WARNING)
module.change_passphrase(
repository_path='repo',
config=config,
local_borg_version='1.2.3',
change_passphrase_arguments=flexmock(),
global_arguments=flexmock(dry_run=False),
)
def test_change_passphrase_calls_borg_with_remote_path_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
-27
View File
@@ -895,33 +895,6 @@ def test_check_archives_with_exit_codes_calls_borg_using_them():
)
def test_check_archives_with_archive_hostname_passes_through_to_borg():
checks = {'repository'}
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
('borg', 'check', '--hostname', 'example.org', '--log-json', 'repo')
)
insert_logging_mock(logging.WARNING)
module.check_archives(
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
check_arguments=flexmock(
progress=None,
repair=None,
only_checks=None,
force=None,
match_archives=None,
max_duration=None,
),
global_arguments=flexmock(),
checks=checks,
archive_filter_flags=(),
)
def test_check_archives_with_remote_path_passes_through_to_borg():
checks = {'repository'}
config = {}
-33
View File
@@ -151,39 +151,6 @@ def test_compact_segments_with_exit_codes_calls_borg_using_them():
)
def test_compact_segments_with_archive_hostname_calls_borg_with_hostname_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
(*COMPACT_COMMAND, '--hostname', 'example.org', '--log-json', 'repo'), logging.INFO
)
insert_logging_mock(logging.WARNING)
module.compact_segments(
dry_run=False,
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
def test_compact_segments_with_remote_path_calls_borg_with_remote_path_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
(*COMPACT_COMMAND, '--remote-path', 'borg1', '--log-json', 'repo'), logging.INFO
)
insert_logging_mock(logging.WARNING)
module.compact_segments(
dry_run=False,
repository_path='repo',
config={},
local_borg_version='1.2.3',
global_arguments=flexmock(),
remote_path='borg1',
)
def test_compact_segments_with_progress_calls_borg_with_progress_flag():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
-1
View File
@@ -518,7 +518,6 @@ def test_make_base_create_command_with_store_config_false_omits_config_files():
('flags', False, False, ('--nobsdflags',)),
('files_changed', 'mtime', True, ('--files-changed', 'mtime')),
('files_cache', 'ctime,size', True, ('--files-cache', 'ctime,size')),
('archive_hostname', 'example.org', True, ('--hostname', 'example.org')),
('umask', 740, True, ('--umask', '740')),
('lock_wait', 5, True, ('--lock-wait', '5')),
),
-26
View File
@@ -78,32 +78,6 @@ def test_make_delete_command_includes_dry_run():
assert command == ('borg', 'delete', '--dry-run', '--log-json', 'repo')
def test_make_delete_command_includes_hostname():
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
'hostname',
'example.org',
).and_return(('--hostname', 'example.org'))
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
('repo',),
)
insert_logging_mock(logging.WARNING)
command = module.make_delete_command(
repository={'path': 'repo'},
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
delete_arguments=flexmock(list_details=False, force=0, match_archives=None, archive=None),
global_arguments=flexmock(dry_run=False),
local_path='borg',
remote_path='borg1',
)
assert command == ('borg', 'delete', '--hostname', 'example.org', '--log-json', 'repo')
def test_make_delete_command_includes_remote_path():
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
-55
View File
@@ -117,61 +117,6 @@ def test_diff_with_local_path_calls_borg_with_it():
)
def test_diff_with_archive_hostname_calls_borg_with_it():
flexmock(module.logging).ANSWER = LOGGING_ANSWER
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return(
flexmock(name='test')
)
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
('--repo', 'repo')
)
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_archive_flags').never()
environment = flexmock()
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
environment
)
flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
full_command=(
'borg',
'diff',
'--hostname',
'example.org',
'--log-json',
'--repo',
'repo',
'archive',
'archive2',
),
output_log_level=LOGGING_ANSWER,
environment=environment,
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
).once()
insert_logging_mock(logging.WARNING)
module.borgmatic.borg.diff.diff(
repository='repo',
archive='archive',
second_archive='archive2',
config={'archive_hostname': 'example.org'},
local_borg_version=None,
diff_arguments=flexmock(
same_chunker_params=False,
sort_keys=[],
content_only=False,
second_archive='archive2',
only_patterns=False,
),
global_arguments=flexmock(),
local_path='borg',
patterns=[],
)
def test_diff_with_remote_path_calls_borg_with_it():
flexmock(module.logging).ANSWER = LOGGING_ANSWER
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
-15
View File
@@ -79,21 +79,6 @@ def test_export_key_calls_borg_using_exit_codes():
)
def test_export_key_calls_borg_with_hostname_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
flexmock(module.os.path).should_receive('exists').never()
insert_execute_command_mock(('borg', 'key', 'export', '--hostname', 'example.org', 'repo'))
insert_logging_mock(logging.WARNING)
module.export_key(
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
export_arguments=flexmock(paper=False, qr_html=False, path=None),
global_arguments=flexmock(dry_run=False),
)
def test_export_key_calls_borg_with_remote_path_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
flexmock(module.os.path).should_receive('exists').never()
-31
View File
@@ -103,37 +103,6 @@ def test_export_tar_archive_calls_borg_using_exit_codes():
)
def test_export_tar_archive_calls_borg_with_hostname_flags():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
insert_execute_command_mock(
(
'borg',
'export-tar',
'--hostname',
'example.org',
'--log-json',
'repo::archive',
'test.tar',
),
)
insert_logging_mock(logging.WARNING)
module.export_tar_archive(
dry_run=False,
repository_path='repo',
archive='archive',
paths=None,
destination_path='test.tar',
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
def test_export_tar_archive_calls_borg_with_remote_path_flags():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
-53
View File
@@ -161,33 +161,6 @@ def test_extract_last_archive_dry_run_calls_borg_using_exit_codes():
)
def test_extract_last_archive_dry_run_calls_borg_with_hostname_flags():
flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
insert_execute_command_mock(
(
'borg',
'extract',
'--dry-run',
'--hostname',
'example.org',
'--log-json',
'repo::archive',
),
)
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
insert_logging_mock(logging.WARNING)
module.extract_last_archive_dry_run(
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
global_arguments=flexmock(),
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(
@@ -332,32 +305,6 @@ def test_extract_archive_calls_borg_with_exit_codes():
)
def test_extract_archive_calls_borg_with_hostname_flags():
flexmock(module.os.path).should_receive('abspath').and_return('repo')
insert_execute_command_mock(
('borg', 'extract', '--hostname', 'example.org', '--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',),
)
flexmock(module.borgmatic.config.validate).should_receive(
'normalize_repository_path',
).and_return('repo')
insert_logging_mock(logging.WARNING)
module.extract_archive(
dry_run=False,
repository='repo',
archive='archive',
paths=None,
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
def test_extract_archive_calls_borg_with_remote_path_flags():
flexmock(module.os.path).should_receive('abspath').and_return('repo')
insert_execute_command_mock(
-18
View File
@@ -79,24 +79,6 @@ def test_import_key_calls_borg_using_exit_codes():
)
def test_import_key_calls_borg_with_hostname_flags():
flexmock(module.flags).should_receive('make_flags').and_return(())
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
flexmock(module.os.path).should_receive('exists').never()
insert_execute_command_mock(
('borg', 'key', 'import', '--hostname', 'example.org', '--log-json', 'repo', '-')
)
insert_logging_mock(logging.WARNING)
module.import_key(
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
import_arguments=flexmock(paper=False, path=None),
global_arguments=flexmock(dry_run=False),
)
def test_import_key_calls_borg_with_remote_path_flags():
flexmock(module.flags).should_receive('make_flags').and_return(())
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
-28
View File
@@ -208,34 +208,6 @@ def test_make_info_command_with_local_path_passes_through_to_command():
assert command == ('borg1', 'info', '--log-json', '--repo', 'repo')
def test_make_info_command_with_archive_hostname_passes_through_to_command():
flexmock(module.flags).should_receive('make_flags').and_return(())
flexmock(module.flags).should_receive('make_flags').with_args(
'hostname',
'example.org',
).and_return(('--hostname', 'example.org'))
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
None,
None,
'2.3.4',
).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'))
insert_logging_mock(logging.WARNING)
command = module.make_info_command(
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='2.3.4',
global_arguments=flexmock(),
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
local_path='borg',
remote_path=None,
)
assert command == ('borg', 'info', '--hostname', 'example.org', '--log-json', '--repo', 'repo')
def test_make_info_command_with_remote_path_passes_through_to_command():
flexmock(module.flags).should_receive('make_flags').and_return(())
flexmock(module.flags).should_receive('make_flags').with_args(
-24
View File
@@ -206,30 +206,6 @@ def test_make_list_command_includes_local_path():
assert command == ('borg2', 'list', '--log-json', 'repo')
def test_make_list_command_includes_hostname():
insert_logging_mock(logging.WARNING)
flexmock(module.flags).should_receive('make_flags').and_return(())
flexmock(module.flags).should_receive('make_flags').with_args(
'hostname',
'example.org',
).and_return(('--hostname', 'example.org'))
flexmock(module.flags).should_receive('make_flags').with_args('log-json', True).and_return(
('--log-json'),
)
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
command = module.make_list_command(
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
list_arguments=flexmock(archive=None, paths=None, format=None, json=False),
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--hostname', 'example.org', '--log-json', 'repo')
def test_make_list_command_includes_remote_path():
insert_logging_mock(logging.WARNING)
flexmock(module.flags).should_receive('make_flags').and_return(())
-21
View File
@@ -150,27 +150,6 @@ def test_mount_archive_calls_borg_using_exit_codes():
)
def test_mount_archive_calls_borg_with_hostname_flags():
flexmock(module.feature).should_receive('available').and_return(False)
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'mount', '--hostname', 'example.org', '--log-json', 'repo::archive', '/mnt'),
)
insert_logging_mock(logging.WARNING)
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive(
repository_path='repo',
archive='archive',
mount_arguments=mount_arguments,
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
def test_mount_archive_calls_borg_with_remote_path_flags():
flexmock(module.feature).should_receive('available').and_return(False)
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
-23
View File
@@ -378,29 +378,6 @@ def test_prune_archives_with_exit_codes_calls_borg_using_them():
)
def test_prune_archives_with_archive_hostname_calls_borg_with_remote_hostname_flags():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
flexmock(module.feature).should_receive('available').with_args(
module.feature.Feature.NO_PRUNE_STATS,
'1.2.3',
).and_return(False)
insert_execute_command_mock((*PRUNE_COMMAND, '--hostname', 'example.org', 'repo'), logging.INFO)
insert_logging_mock(logging.WARNING)
prune_arguments = flexmock(statistics=False, list_details=False)
module.prune_archives(
dry_run=False,
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
global_arguments=flexmock(),
prune_arguments=prune_arguments,
)
def test_prune_archives_with_remote_path_calls_borg_with_remote_path_flags():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
-37
View File
@@ -92,43 +92,6 @@ def test_recreate_with_dry_run_calls_borg_with_dry_run_flag():
)
def test_recreate_with_archive_hostname():
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return(None)
flexmock(module.borgmatic.borg.flags).should_receive('make_list_filter_flags').and_return('')
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
flexmock(module.borgmatic.borg.flags).should_receive(
'make_repository_archive_flags',
).and_return(
(
'--repo',
'repo',
),
)
insert_execute_command_mock(
('borg', 'recreate', '--hostname', 'example.org', '--log-json', '--repo', 'repo')
)
insert_logging_mock(logging.WARNING)
module.recreate_archive(
repository='repo',
archive='archive',
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
recreate_arguments=flexmock(
list=None,
target=None,
comment=None,
timestamp=None,
match_archives=None,
),
global_arguments=flexmock(dry_run=False),
local_path='borg',
patterns=None,
)
def test_recreate_with_remote_path():
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return(None)
-24
View File
@@ -433,30 +433,6 @@ def test_create_repository_with_exit_codes_calls_borg_using_them():
)
def test_create_repository_with_archive_hostname_calls_borg_with_hostname_flag():
insert_repo_info_command_not_found_mock()
insert_repo_create_command_mock(
(*REPO_CREATE_COMMAND, '--hostname', 'example.org', '--repo', 'repo'),
)
insert_logging_mock(logging.WARNING)
flexmock(module.feature).should_receive('available').and_return(True)
flexmock(module.flags).should_receive('make_repository_flags').and_return(
(
'--repo',
'repo',
),
)
module.create_repository(
dry_run=False,
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='2.3.4',
global_arguments=flexmock(),
encryption_mode='repokey',
)
def test_create_repository_with_remote_path_calls_borg_with_remote_path_flag():
insert_repo_info_command_not_found_mock()
insert_repo_create_command_mock(
-27
View File
@@ -126,33 +126,6 @@ def test_make_repo_delete_command_includes_dry_run():
assert command == ('borg', 'repo-delete', '--dry-run', '--log-json', 'repo')
def test_make_repo_delete_command_includes_hostname():
insert_logging_mock(logging.WARNING)
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
'hostname',
'example.org',
).and_return(('--hostname', 'example.org'))
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
('repo',),
)
command = module.make_repo_delete_command(
repository={'path': 'repo'},
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
repo_delete_arguments=flexmock(list_details=False, force=0),
global_arguments=flexmock(dry_run=False),
local_path='borg',
remote_path=None,
output_file=None,
)
assert command == ('borg', 'repo-delete', '--hostname', 'example.org', '--log-json', 'repo')
def test_make_repo_delete_command_includes_remote_path():
insert_logging_mock(logging.WARNING)
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
-51
View File
@@ -364,57 +364,6 @@ def test_display_repository_info_with_exit_codes_calls_borg_using_them():
)
def test_display_repository_info_with_archve_hostname_calls_borg_with_hostname_flags():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
flexmock(module.feature).should_receive('available').and_return(True)
flexmock(module.flags).should_receive('make_flags').replace_with(
lambda name, value: (f'--{name}', value) if value else (),
)
flexmock(module.flags).should_receive('make_repository_flags').and_return(
(
'--repo',
'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_and_capture_output').with_args(
(
'borg',
'repo-info',
'--hostname',
'example.org',
'--log-json',
'--json',
'--repo',
'repo',
),
environment=None,
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
).and_yield('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'repo-info', '--hostname', 'example.org', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
)
insert_logging_mock(logging.WARNING)
module.display_repository_info(
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='2.3.4',
repo_info_arguments=flexmock(json=False),
global_arguments=flexmock(),
)
def test_display_repository_info_with_remote_path_calls_borg_with_remote_path_flags():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
-66
View File
@@ -265,40 +265,6 @@ def test_get_latest_archive_with_exit_codes_calls_borg_using_them():
)
def test_get_latest_archive_with_archive_hostname_calls_borg_with_hostname_flags():
expected_archive = {'name': 'archive-name', 'id': 'd34db33f'}
flexmock(module.feature).should_receive('available').and_return(False)
flexmock(module.flags).should_receive('make_flags').and_return(())
flexmock(module.flags).should_receive('make_flags').with_args(
'hostname', 'example.org'
).and_return(('--hostname', 'example.org'))
flexmock(module.flags).should_receive('make_flags').with_args('last', 1).and_return(
('--last', '1')
)
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
flexmock(module.flags).should_receive('make_repository_flags').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_and_capture_output').with_args(
('borg', 'list', '--hostname', 'example.org', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
environment=None,
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
).and_yield(json.dumps({'archives': [expected_archive]}))
insert_logging_mock(logging.WARNING)
assert (
module.get_latest_archive(
'repo',
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
== expected_archive
)
def test_get_latest_archive_with_remote_path_calls_borg_with_remote_path_flags():
expected_archive = {'name': 'archive-name', 'id': 'd34db33f'}
flexmock(module.feature).should_receive('available').and_return(False)
@@ -916,38 +882,6 @@ def test_make_repo_list_command_includes_local_path():
assert command == ('borg2', 'list', '--log-json', 'repo')
def test_make_repo_list_command_includes_hostname():
flexmock(module.feature).should_receive('available').and_return(False)
flexmock(module.flags).should_receive('make_flags').replace_with(
lambda name, value: (f'--{name}', value) if value else (),
)
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
None,
None,
'1.2.3',
).and_return(())
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_logging_mock(logging.WARNING)
command = module.make_repo_list_command(
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='1.2.3',
repo_list_arguments=flexmock(
archive=None,
paths=None,
format=None,
json=False,
prefix=None,
match_archives=None,
),
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--hostname', 'example.org', '--log-json', 'repo')
def test_make_repo_list_command_includes_remote_path():
flexmock(module.feature).should_receive('available').and_return(False)
flexmock(module.flags).should_receive('make_flags').replace_with(
-39
View File
@@ -340,45 +340,6 @@ def test_transfer_archives_with_exit_codes_calls_borg_using_them():
)
def test_transfer_archives_with_archive_hostname_calls_borg_with_hostname_flags():
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').with_args(
'hostname',
'example.org',
).and_return(('--hostname', 'example.org'))
flexmock(module.flags).should_receive('make_match_archives_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.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
flexmock(module).should_receive('execute_command').with_args(
('borg', 'transfer', '--hostname', 'example.org', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
)
insert_logging_mock(logging.WARNING)
module.transfer_archives(
dry_run=False,
repository_path='repo',
config={'archive_hostname': 'example.org'},
local_borg_version='2.3.4',
transfer_arguments=flexmock(
archive=None,
progress=None,
match_archives=None,
source_repository=None,
),
global_arguments=flexmock(),
)
def test_transfer_archives_with_remote_path_calls_borg_with_remote_path_flags():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER