Get several existing tests passing and refactor logging of lines from external programs.

This commit is contained in:
Dan Helfman
2025-12-30 22:25:12 -08:00
parent 7388e6f5b9
commit 9f6cce2a39
39 changed files with 1042 additions and 975 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
2.0.14.dev0
2.1.0.dev0
* #485: When running commands (database clients, command hooks, etc.), elevate stderr output to
borgmatic error logs.
* #858: With the "--log-json" flag, log borgmatic's own logs as JSON, not just Borg's.
+7 -1
View File
@@ -176,7 +176,13 @@ def check_archives(
+ make_check_name_flags(checks_subset, archive_filter_flags)
+ (('--remote-path', remote_path) if remote_path else ())
+ (('--umask', str(umask)) if umask else ())
+ ('--log-json',)
+ (
('--log-json',)
if (
config.get('log_json') or not (check_arguments.repair or config.get('progress'))
)
else ()
)
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
+ verbosity_flags
+ (('--progress',) if config.get('progress') else ())
+1 -1
View File
@@ -31,7 +31,7 @@ def compact_segments(
(local_path, 'compact')
+ (('--remote-path', remote_path) if remote_path else ())
+ (('--umask', str(umask)) if umask else ())
+ ('--log-json',)
+ (('--log-json',) if (config.get('log_json') or not config.get('progress')) else ())
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
+ (('--progress',) if config.get('progress') else ())
+ (('--cleanup-commits',) if cleanup_commits else ())
+1 -1
View File
@@ -217,8 +217,8 @@ def make_base_create_command(
+ (('--files-cache', files_cache) if files_cache else ())
+ (('--remote-path', remote_path) if remote_path else ())
+ (('--umask', str(umask)) if umask else ())
+ ('--log-json',)
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
+ (('--log-json',) if (config.get('log_json') or not config.get('progress')) else ())
+ (
('--list', '--filter', list_filter_flags)
if config.get('list_details') and not json and not config.get('progress')
+1 -1
View File
@@ -127,7 +127,7 @@ def extract_archive(
+ (('--remote-path', remote_path) if remote_path else ())
+ numeric_ids_flags
+ (('--umask', str(umask)) if umask else ())
+ ('--log-json',)
+ (('--log-json',) if (config.get('log_json') or not config.get('progress')) else ())
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
+ (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
+1 -1
View File
@@ -72,9 +72,9 @@ def prune_archives(
full_command = (
(local_path, 'prune')
+ make_prune_flags(config, prune_arguments, local_borg_version)
+ ('--log-json',)
+ (('--remote-path', remote_path) if remote_path else ())
+ (('--umask', str(umask)) if umask else ())
+ ('--log-json',)
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
+ (
('--stats',)
+1
View File
@@ -1,6 +1,7 @@
import logging
import shlex
import borgmatic.borg.environment
import borgmatic.borg.flags
logger = logging.getLogger(__name__)
+1 -1
View File
@@ -81,6 +81,7 @@ def create_repository(
if feature.available(feature.Feature.REPO_CREATE, local_borg_version)
else ('init',)
)
+ ('--log-json',)
+ (('--encryption', encryption_mode) if encryption_mode else ())
+ (('--other-repo', source_repository) if source_repository else ())
+ (('--copy-crypt-key',) if copy_crypt_key else ())
@@ -89,7 +90,6 @@ def create_repository(
+ (('--make-parent-dirs',) if make_parent_directories else ())
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
+ (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ())
+ ('--log-json',)
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
+ (('--remote-path', remote_path) if remote_path else ())
+ (('--umask', str(umask)) if umask else ())
+1 -1
View File
@@ -77,7 +77,7 @@ def get_latest_archive(
),
*flags.make_flags('remote-path', remote_path),
*flags.make_flags('umask', config.get('umask')),
+ ('--log-json',)
*('--log-json',),
*flags.make_flags('lock-wait', config.get('lock_wait')),
*(
flags.make_flags('consider-checkpoints', consider_checkpoints)
+1 -1
View File
@@ -33,7 +33,7 @@ def transfer_archives(
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
+ flags.make_flags('remote-path', remote_path)
+ flags.make_flags('umask', config.get('umask'))
+ ('--log-json',)
+ (('--log-json',) if (config.get('log_json') or not config.get('progress')) else ())
+ flags.make_flags('lock-wait', config.get('lock_wait'))
+ flags.make_flags('progress', config.get('progress'))
+ (
+1
View File
@@ -15,6 +15,7 @@ def unmount_archive(config, mount_point, local_path='borg'):
extra_borg_options = config.get('extra_borg_options', {}).get('umount', '')
full_command = (
(local_path, 'umount')
+ ('--log-json',)
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
+ (tuple(shlex.split(extra_borg_options)) if extra_borg_options else ())
+6 -1
View File
@@ -700,7 +700,12 @@ def load_configurations(config_filenames, arguments, overrides=None, resolve_env
),
),
logging.makeLogRecord(
dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg=str(error), name=logger.name),
dict(
levelno=logging.CRITICAL,
levelname='CRITICAL',
msg=str(error),
name=logger.name,
),
),
],
)
+51 -32
View File
@@ -107,12 +107,25 @@ def borg_log_data_to_log_record(log_data):
)
def log_line(last_lines, captured_output, line, default_log_level, came_from_stderr, borg_local_path, command):
def line_to_log_record(line, log_level):
'''
Given a rolling list of last lines, a list of captured output, the line to be logged, a default
log level, whether the this log line came from stderr, the Borg local path, and the command as a
sequence, append the line to the last lines and (if the log level is None) the captured output.
Then log the line at the requested log level.
Given a log data dict for a single Borg log entry, return it converted to a logging.LogRecord
instance.
'''
return logging.makeLogRecord(
dict(
msg=line,
levelno=log_level,
levelname=logging.getLevelName(log_level),
)
)
def parse_line(line, log_level, came_from_stderr, borg_local_path, command):
'''
Given a raw output line from an external program, whether this line came from stderr, the Borg
local path, and the command as a sequence, return a logging.LogRecord instance containing its
parsed data.
If the command being run is Borg, and the log line is JSON-formatted log data, then grab the log
level from it and log the parsed JSON to be consumed later by a Python logging.Formatter.
@@ -121,32 +134,34 @@ def log_line(last_lines, captured_output, line, default_log_level, came_from_std
came from stderr and the string "warning:" appears at the start of the log line. In that case,
just elevate the log level to a WARN.
'''
log_message = line
log_level = default_log_level
line_data = None
if borg_local_path and command[0] == borg_local_path:
with contextlib.suppress(json.JSONDecodeError, TypeError, KeyError):
line_data = json.loads(line)
borg_level_name = line_data['levelname']
log_message = line_data['message']
log_level = logging._nameToLevel.get(borg_level_name)
return borg_log_data_to_log_record(json.loads(line))
elif came_from_stderr:
log_level = logging.WARNING if line.lower().startswith('warning:') else logging.ERROR
return line_to_log_record(
line, logging.WARNING if line.lower().startswith('warning:') else logging.ERROR
)
return line_to_log_record(line, log_level)
def handle_log_record(log_record, last_lines, captured_output):
'''
Given a log record to be logged, a rolling list of last lines, and a list of captured output,
append the record's message to the last lines and (if its log level is None) the captured
output. Then log the line.
'''
log_message = log_record.getMessage()
last_lines.append(log_message)
if len(last_lines) > ERROR_OUTPUT_MAX_LINE_COUNT:
last_lines.pop(0)
if log_level is None:
if log_record.levelno is None:
captured_output.append(log_message)
return
if line_data:
logger.handle(borg_log_data_to_log_record(line_data))
else:
logger.log(log_level, log_message)
logger.handle(log_record)
def log_outputs(processes, exclude_stdouts, output_log_level, borg_local_path, borg_exit_codes): # noqa: PLR0912
@@ -208,16 +223,18 @@ def log_outputs(processes, exclude_stdouts, output_log_level, borg_local_path, b
else ready_process.args
)
# Keep the last few lines of output in case the process errors, and we need the
# Keep the last few lines of output in case the process errors and we need the
# output for the exception below.
log_line(
handle_log_record(
parse_line(
line=line,
log_level=output_log_level,
came_from_stderr=(ready_buffer == ready_process.stderr),
borg_local_path=borg_local_path,
command=command,
),
last_lines=buffer_last_lines[ready_buffer],
captured_output=captured_outputs[ready_process],
line=line,
default_log_level=output_log_level,
came_from_stderr=(ready_buffer == ready_process.stderr),
borg_local_path=borg_local_path,
command=command,
)
if not still_running:
@@ -248,14 +265,16 @@ def log_outputs(processes, exclude_stdouts, output_log_level, borg_local_path, b
if not line:
break
log_line(
handle_log_record(
parse_line(
line=line,
log_level=output_log_level,
came_from_stderr=(output_buffer == process.stderr),
borg_local_path=borg_local_path,
command=command,
),
last_lines=last_lines,
captured_output=captured_outputs[process],
line=line,
default_log_level=output_log_level,
came_from_stderr=(output_buffer == process.stderr),
borg_local_path=borg_local_path,
command=command,
)
if len(last_lines) == ERROR_OUTPUT_MAX_LINE_COUNT:
+7 -8
View File
@@ -114,7 +114,9 @@ class JournaldHandler(logging.Handler):
entry = dict(
LOGGER_NAME=record.name,
MESSAGE=record.getMessage(),
PRIORITY=self.log_level_to_journald_priority.get(record.levelno, DEFAULT_JOURNALD_PRIORITY),
PRIORITY=self.log_level_to_journald_priority.get(
record.levelno, DEFAULT_JOURNALD_PRIORITY
),
SYSLOG_IDENTIFIER='borgmatic',
SYSLOG_PID=os.getpid(),
UNIT=record.name,
@@ -462,11 +464,7 @@ def configure_logging(
handlers.append(journald_handler)
else:
syslog_path = next(
(
path
for path in SYSLOG_PATHS
if os.path.exists(path)
),
(path for path in SYSLOG_PATHS if os.path.exists(path)),
None,
)
@@ -483,8 +481,9 @@ def configure_logging(
if log_file and log_file_log_level != logging.DISABLED:
file_handler = logging.handlers.WatchedFileHandler(log_file)
file_handler.setFormatter(
Json_formatter() if log_json else
Log_prefix_formatter(
Json_formatter()
if log_json
else Log_prefix_formatter(
log_file_format or '[{asctime}] {levelname}: {prefix}{message}',
),
)
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "borgmatic"
version = "2.0.14.dev0"
version = "2.1.0.dev0"
authors = [
{ name="Dan Helfman", email="witten@torsion.org" },
]
+49 -6
View File
@@ -1,7 +1,17 @@
import logging
from flexmock import flexmock
from borgmatic.borg import rename as module
from tests.unit.test_verbosity import insert_logging_mock
def insert_logging_mock(log_level):
'''
Mock the isEnabledFor from Python logging.
'''
logging = flexmock(module.logging.Logger)
logging.should_receive('isEnabledFor').replace_with(lambda level: level >= log_level)
logging.should_receive('getEffectiveLevel').replace_with(lambda: log_level)
def test_make_rename_command_includes_log_info():
@@ -18,7 +28,7 @@ def test_make_rename_command_includes_log_info():
remote_path=None,
)
assert command == ('borg', 'rename', '--info', 'repo::old_archive', 'new_archive')
assert command == ('borg', 'rename', '--info', '--log-json', 'repo::old_archive', 'new_archive')
def test_make_rename_command_includes_log_debug():
@@ -35,7 +45,15 @@ def test_make_rename_command_includes_log_debug():
remote_path=None,
)
assert command == ('borg', 'rename', '--debug', '--show-rc', 'repo::old_archive', 'new_archive')
assert command == (
'borg',
'rename',
'--debug',
'--show-rc',
'--log-json',
'repo::old_archive',
'new_archive',
)
def test_make_rename_command_includes_dry_run():
@@ -50,7 +68,14 @@ def test_make_rename_command_includes_dry_run():
remote_path=None,
)
assert command == ('borg', 'rename', '--dry-run', 'repo::old_archive', 'new_archive')
assert command == (
'borg',
'rename',
'--dry-run',
'--log-json',
'repo::old_archive',
'new_archive',
)
def test_make_rename_command_includes_remote_path():
@@ -70,6 +95,7 @@ def test_make_rename_command_includes_remote_path():
'rename',
'--remote-path',
'borg1',
'--log-json',
'repo::old_archive',
'new_archive',
)
@@ -87,7 +113,15 @@ def test_make_rename_command_includes_umask():
remote_path=None,
)
assert command == ('borg', 'rename', '--umask', '077', 'repo::old_archive', 'new_archive')
assert command == (
'borg',
'rename',
'--umask',
'077',
'--log-json',
'repo::old_archive',
'new_archive',
)
def test_make_rename_command_includes_log_json():
@@ -117,7 +151,15 @@ def test_make_rename_command_includes_lock_wait():
remote_path=None,
)
assert command == ('borg', 'rename', '--lock-wait', '5', 'repo::old_archive', 'new_archive')
assert command == (
'borg',
'rename',
'--log-json',
'--lock-wait',
'5',
'repo::old_archive',
'new_archive',
)
def test_make_rename_command_includes_extra_borg_options():
@@ -135,6 +177,7 @@ def test_make_rename_command_includes_extra_borg_options():
assert command == (
'borg',
'rename',
'--log-json',
'--extra',
'value with space',
'repo::old_archive',
+60 -40
View File
@@ -9,21 +9,35 @@ from borgmatic import execute as module
def test_log_outputs_logs_each_line_separately():
flexmock(module.logger).should_receive('log').with_args(logging.INFO, 'hi').once()
flexmock(module.logger).should_receive('log').with_args(logging.INFO, 'there').once()
hi_record = flexmock(
msg='hi',
levelno=logging.INFO,
levelname='INFO',
getMessage=lambda: 'hi',
)
flexmock(module).should_receive('line_to_log_record').with_args('hi', logging.INFO).and_return(hi_record)
flexmock(module.logger).should_receive('handle').with_args(hi_record).once()
there_record = flexmock(
msg='there',
levelno=logging.INFO,
levelname='INFO',
getMessage=lambda: 'there',
)
flexmock(module).should_receive('line_to_log_record').with_args('there', logging.INFO).and_return(there_record)
flexmock(module.logger).should_receive('handle').with_args(there_record).once()
flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.SUCCESS)
hi_process = subprocess.Popen(['echo', 'hi'], stdout=subprocess.PIPE)
flexmock(module).should_receive('output_buffer_for_process').with_args(
flexmock(module).should_receive('output_buffers_for_process').with_args(
hi_process,
(),
).and_return(hi_process.stdout)
).and_return((hi_process.stdout,))
there_process = subprocess.Popen(['echo', 'there'], stdout=subprocess.PIPE)
flexmock(module).should_receive('output_buffer_for_process').with_args(
flexmock(module).should_receive('output_buffers_for_process').with_args(
there_process,
(),
).and_return(there_process.stdout)
).and_return((there_process.stdout,))
module.log_outputs(
(hi_process, there_process),
@@ -35,21 +49,28 @@ def test_log_outputs_logs_each_line_separately():
def test_log_outputs_skips_logs_for_process_with_none_stdout():
flexmock(module.logger).should_receive('log').with_args(logging.INFO, 'hi').never()
flexmock(module.logger).should_receive('log').with_args(logging.INFO, 'there').once()
flexmock(module).should_receive('line_to_log_record').with_args('hi', logging.INFO).never()
there_record = flexmock(
msg='there',
levelno=logging.INFO,
levelname='INFO',
getMessage=lambda: 'there',
)
flexmock(module).should_receive('line_to_log_record').with_args('there', logging.INFO).and_return(there_record)
flexmock(module.logger).should_receive('handle').with_args(there_record).once()
flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.SUCCESS)
hi_process = subprocess.Popen(['echo', 'hi'], stdout=None)
flexmock(module).should_receive('output_buffer_for_process').with_args(
flexmock(module).should_receive('output_buffers_for_process').with_args(
hi_process,
(),
).and_return(hi_process.stdout)
).and_return((hi_process.stdout,))
there_process = subprocess.Popen(['echo', 'there'], stdout=subprocess.PIPE)
flexmock(module).should_receive('output_buffer_for_process').with_args(
flexmock(module).should_receive('output_buffers_for_process').with_args(
there_process,
(),
).and_return(there_process.stdout)
).and_return((there_process.stdout,))
module.log_outputs(
(hi_process, there_process),
@@ -65,16 +86,16 @@ def test_log_outputs_returns_output_without_logging_for_output_log_level_none():
flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.SUCCESS)
hi_process = subprocess.Popen(['echo', 'hi'], stdout=subprocess.PIPE)
flexmock(module).should_receive('output_buffer_for_process').with_args(
flexmock(module).should_receive('output_buffers_for_process').with_args(
hi_process,
(),
).and_return(hi_process.stdout)
).and_return((hi_process.stdout,))
there_process = subprocess.Popen(['echo', 'there'], stdout=subprocess.PIPE)
flexmock(module).should_receive('output_buffer_for_process').with_args(
flexmock(module).should_receive('output_buffers_for_process').with_args(
there_process,
(),
).and_return(there_process.stdout)
).and_return((there_process.stdout,))
captured_outputs = module.log_outputs(
(hi_process, there_process),
@@ -93,7 +114,7 @@ def test_log_outputs_includes_error_output_in_exception():
flexmock(module).should_receive('command_for_process').and_return('grep')
process = subprocess.Popen(['grep'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
flexmock(module).should_receive('output_buffer_for_process').and_return(process.stdout)
flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,))
with pytest.raises(subprocess.CalledProcessError) as error:
module.log_outputs(
@@ -112,7 +133,6 @@ def test_log_outputs_logs_multiline_error_output():
Make sure that all error output lines get logged, not just (for instance) the first few lines
of a process' traceback.
'''
flexmock(module.logger).should_receive('log')
flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.ERROR)
flexmock(module).should_receive('command_for_process').and_return('grep')
@@ -121,8 +141,8 @@ def test_log_outputs_logs_multiline_error_output():
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
flexmock(module).should_receive('output_buffer_for_process').and_return(process.stdout)
flexmock(module.logger).should_call('log').at_least().times(3)
flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,))
flexmock(module.logger).should_call('handle').at_least().times(3)
with pytest.raises(subprocess.CalledProcessError):
module.log_outputs(
@@ -140,7 +160,7 @@ def test_log_outputs_skips_error_output_in_exception_for_process_with_none_stdou
flexmock(module).should_receive('command_for_process').and_return('grep')
process = subprocess.Popen(['grep'], stdout=None)
flexmock(module).should_receive('output_buffer_for_process').and_return(process.stdout)
flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,))
with pytest.raises(subprocess.CalledProcessError) as error:
module.log_outputs(
@@ -183,13 +203,13 @@ def test_log_outputs_kills_other_processes_and_raises_when_one_errors():
'borg',
None,
).and_return(module.Exit_status.SUCCESS)
flexmock(module).should_receive('output_buffer_for_process').with_args(process, ()).and_return(
process.stdout,
flexmock(module).should_receive('output_buffers_for_process').with_args(process, ()).and_return(
(process.stdout,),
)
flexmock(module).should_receive('output_buffer_for_process').with_args(
flexmock(module).should_receive('output_buffers_for_process').with_args(
other_process,
(),
).and_return(other_process.stdout)
).and_return((other_process.stdout,))
flexmock(other_process).should_receive('kill').once()
with pytest.raises(subprocess.CalledProcessError) as error:
@@ -233,13 +253,13 @@ def test_log_outputs_kills_other_processes_and_returns_when_one_exits_with_warni
'borg',
None,
).and_return(module.Exit_status.SUCCESS)
flexmock(module).should_receive('output_buffer_for_process').with_args(process, ()).and_return(
process.stdout,
flexmock(module).should_receive('output_buffers_for_process').with_args(process, ()).and_return(
(process.stdout,),
)
flexmock(module).should_receive('output_buffer_for_process').with_args(
flexmock(module).should_receive('output_buffers_for_process').with_args(
other_process,
(),
).and_return(other_process.stdout)
).and_return((other_process.stdout,))
flexmock(other_process).should_receive('kill').once()
module.log_outputs(
@@ -276,14 +296,14 @@ def test_log_outputs_vents_other_processes_when_one_exits():
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
flexmock(module).should_receive('output_buffer_for_process').with_args(
flexmock(module).should_receive('output_buffers_for_process').with_args(
process,
(process.stdout,),
).and_return(process.stderr)
flexmock(module).should_receive('output_buffer_for_process').with_args(
).and_return((process.stderr,))
flexmock(module).should_receive('output_buffers_for_process').with_args(
other_process,
(process.stdout,),
).and_return(other_process.stdout)
).and_return((other_process.stdout,))
flexmock(process.stdout).should_call('readline').at_least().once()
module.log_outputs(
@@ -314,14 +334,14 @@ def test_log_outputs_does_not_error_when_one_process_exits():
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
flexmock(module).should_receive('output_buffer_for_process').with_args(
flexmock(module).should_receive('output_buffers_for_process').with_args(
process,
(process.stdout,),
).and_return(process.stderr)
flexmock(module).should_receive('output_buffer_for_process').with_args(
).and_return((process.stderr,))
flexmock(module).should_receive('output_buffers_for_process').with_args(
other_process,
(process.stdout,),
).and_return(other_process.stdout)
).and_return((other_process.stdout,))
module.log_outputs(
(process, other_process),
@@ -349,7 +369,7 @@ def test_log_outputs_truncates_long_error_output():
'borg',
None,
).and_return(module.Exit_status.ERROR)
flexmock(module).should_receive('output_buffer_for_process').and_return(process.stdout)
flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,))
with pytest.raises(subprocess.CalledProcessError) as error:
flexmock(module, ERROR_OUTPUT_MAX_LINE_COUNT=0).log_outputs(
@@ -369,7 +389,7 @@ def test_log_outputs_with_no_output_logs_nothing():
flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.SUCCESS)
process = subprocess.Popen(['true'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
flexmock(module).should_receive('output_buffer_for_process').and_return(process.stdout)
flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,))
module.log_outputs(
(process,),
@@ -386,7 +406,7 @@ def test_log_outputs_with_unfinished_process_re_polls():
process = subprocess.Popen(['true'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
flexmock(process).should_receive('poll').and_return(None).and_return(0).times(3)
flexmock(module).should_receive('output_buffer_for_process').and_return(process.stdout)
flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,))
module.log_outputs(
(process,),
+18 -22
View File
@@ -23,7 +23,7 @@ def insert_execute_command_mock(command, working_directory=None, borg_exit_codes
def test_break_lock_calls_borg_with_required_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'break-lock', 'repo'))
insert_execute_command_mock(('borg', 'break-lock', '--log-json', 'repo'))
module.break_lock(
repository_path='repo',
@@ -35,7 +35,7 @@ def test_break_lock_calls_borg_with_required_flags():
def test_break_lock_calls_borg_with_local_path():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg1', 'break-lock', 'repo'))
insert_execute_command_mock(('borg1', 'break-lock', '--log-json', 'repo'))
module.break_lock(
repository_path='repo',
@@ -48,7 +48,7 @@ def test_break_lock_calls_borg_with_local_path():
def test_break_lock_calls_borg_using_exit_codes():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg1', 'break-lock', 'repo'))
insert_execute_command_mock(('borg1', 'break-lock', '--log-json', 'repo'))
module.break_lock(
repository_path='repo',
@@ -61,7 +61,9 @@ def test_break_lock_calls_borg_using_exit_codes():
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(('borg', 'break-lock', '--remote-path', 'borg1', 'repo'))
insert_execute_command_mock(
('borg', 'break-lock', '--remote-path', 'borg1', '--log-json', 'repo')
)
module.break_lock(
repository_path='repo',
@@ -74,7 +76,7 @@ def test_break_lock_calls_borg_with_remote_path_flags():
def test_break_lock_calls_borg_with_umask_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'break-lock', '--umask', '0770', 'repo'))
insert_execute_command_mock(('borg', 'break-lock', '--umask', '0770', '--log-json', 'repo'))
module.break_lock(
repository_path='repo',
@@ -84,21 +86,9 @@ def test_break_lock_calls_borg_with_umask_flags():
)
def test_break_lock_calls_borg_with_log_json_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'break-lock', '--log-json', 'repo'))
module.break_lock(
repository_path='repo',
config={'log_json': True},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
def test_break_lock_calls_borg_with_lock_wait_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'break-lock', '--lock-wait', '5', 'repo'))
insert_execute_command_mock(('borg', 'break-lock', '--log-json', '--lock-wait', '5', 'repo'))
module.break_lock(
repository_path='repo',
@@ -110,7 +100,9 @@ def test_break_lock_calls_borg_with_lock_wait_flags():
def test_break_lock_calls_borg_with_extra_borg_options():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'break-lock', '--extra', 'value with space', 'repo'))
insert_execute_command_mock(
('borg', 'break-lock', '--log-json', '--extra', 'value with space', 'repo')
)
module.break_lock(
repository_path='repo',
@@ -122,7 +114,7 @@ def test_break_lock_calls_borg_with_extra_borg_options():
def test_break_lock_with_log_info_calls_borg_with_info_parameter():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'break-lock', '--info', 'repo'))
insert_execute_command_mock(('borg', 'break-lock', '--log-json', '--info', 'repo'))
insert_logging_mock(logging.INFO)
module.break_lock(
@@ -135,7 +127,9 @@ def test_break_lock_with_log_info_calls_borg_with_info_parameter():
def test_break_lock_with_log_debug_calls_borg_with_debug_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'break-lock', '--debug', '--show-rc', 'repo'))
insert_execute_command_mock(
('borg', 'break-lock', '--log-json', '--debug', '--show-rc', 'repo')
)
insert_logging_mock(logging.DEBUG)
module.break_lock(
@@ -148,7 +142,9 @@ def test_break_lock_with_log_debug_calls_borg_with_debug_flags():
def test_break_lock_calls_borg_with_working_directory():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'break-lock', 'repo'), working_directory='/working/dir')
insert_execute_command_mock(
('borg', 'break-lock', '--log-json', 'repo'), working_directory='/working/dir'
)
module.break_lock(
repository_path='repo',
+13 -28
View File
@@ -34,7 +34,7 @@ def insert_execute_command_mock(
def test_change_passphrase_calls_borg_with_required_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'key', 'change-passphrase', 'repo'))
insert_execute_command_mock(('borg', 'key', 'change-passphrase', '--log-json', 'repo'))
module.change_passphrase(
repository_path='repo',
@@ -47,7 +47,7 @@ def test_change_passphrase_calls_borg_with_required_flags():
def test_change_passphrase_calls_borg_with_local_path():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg1', 'key', 'change-passphrase', 'repo'))
insert_execute_command_mock(('borg1', 'key', 'change-passphrase', '--log-json', 'repo'))
module.change_passphrase(
repository_path='repo',
@@ -64,7 +64,7 @@ def test_change_passphrase_calls_borg_using_exit_codes():
borg_exit_codes = flexmock()
config = {'borg_exit_codes': borg_exit_codes}
insert_execute_command_mock(
('borg', 'key', 'change-passphrase', 'repo'),
('borg', 'key', 'change-passphrase', '--log-json', 'repo'),
config=config,
borg_exit_codes=borg_exit_codes,
)
@@ -81,7 +81,7 @@ def test_change_passphrase_calls_borg_using_exit_codes():
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(
('borg', 'key', 'change-passphrase', '--remote-path', 'borg1', 'repo'),
('borg', 'key', 'change-passphrase', '--remote-path', 'borg1', '--log-json', 'repo'),
)
module.change_passphrase(
@@ -98,24 +98,7 @@ def test_change_passphrase_calls_borg_with_umask_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
config = {'umask': '0770'}
insert_execute_command_mock(
('borg', 'key', 'change-passphrase', '--umask', '0770', 'repo'),
config=config,
)
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_log_json_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
config = {'log_json': True}
insert_execute_command_mock(
('borg', 'key', 'change-passphrase', '--log-json', 'repo'),
('borg', 'key', 'change-passphrase', '--umask', '0770', '--log-json', 'repo'),
config=config,
)
@@ -132,7 +115,7 @@ def test_change_passphrase_calls_borg_with_lock_wait_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
config = {'lock_wait': '5'}
insert_execute_command_mock(
('borg', 'key', 'change-passphrase', '--lock-wait', '5', 'repo'),
('borg', 'key', 'change-passphrase', '--log-json', '--lock-wait', '5', 'repo'),
config=config,
)
@@ -149,7 +132,7 @@ def test_change_passphrase_calls_borg_with_extra_borg_options():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
config = {'extra_borg_options': {'key_change_passphrase': '--extra "value with space"'}}
insert_execute_command_mock(
('borg', 'key', 'change-passphrase', '--extra', 'value with space', 'repo'),
('borg', 'key', 'change-passphrase', '--log-json', '--extra', 'value with space', 'repo'),
config=config,
)
@@ -164,7 +147,9 @@ def test_change_passphrase_calls_borg_with_extra_borg_options():
def test_change_passphrase_with_log_info_calls_borg_with_info_parameter():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'key', 'change-passphrase', '--info', 'repo'))
insert_execute_command_mock(
('borg', 'key', 'change-passphrase', '--log-json', '--info', 'repo')
)
insert_logging_mock(logging.INFO)
module.change_passphrase(
@@ -179,7 +164,7 @@ def test_change_passphrase_with_log_info_calls_borg_with_info_parameter():
def test_change_passphrase_with_log_debug_calls_borg_with_debug_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
('borg', 'key', 'change-passphrase', '--debug', '--show-rc', 'repo'),
('borg', 'key', 'change-passphrase', '--log-json', '--debug', '--show-rc', 'repo'),
)
insert_logging_mock(logging.DEBUG)
@@ -209,7 +194,7 @@ def test_change_passphrase_with_dry_run_skips_borg_call():
def test_change_passphrase_calls_borg_without_passphrase():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
('borg', 'key', 'change-passphrase', 'repo'),
('borg', 'key', 'change-passphrase', '--log-json', 'repo'),
config={'option': 'foo'},
)
@@ -230,7 +215,7 @@ def test_change_passphrase_calls_borg_with_working_directory():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
config = {'working_directory': '/working/dir'}
insert_execute_command_mock(
('borg', 'key', 'change-passphrase', 'repo'),
('borg', 'key', 'change-passphrase', '--log-json', 'repo'),
config=config,
working_directory='/working/dir',
)
+104 -49
View File
@@ -356,6 +356,42 @@ def test_check_archives_with_progress_passes_through_to_borg():
)
def test_check_archives_with_log_json_and_progress_passes_through_both_to_borg():
config = {'log_json': True, 'progress': True}
flexmock(module).should_receive('make_check_name_flags').with_args(
{'repository'},
(),
).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').with_args(
('borg', 'check', '--log-json', '--progress', 'repo'),
output_file=module.DO_NOT_CAPTURE,
environment=None,
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
).once()
module.check_archives(
repository_path='repo',
config=config,
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={'repository'},
archive_filter_flags=(),
)
def test_check_archives_with_repair_passes_through_to_borg():
config = {}
flexmock(module).should_receive('make_check_name_flags').with_args(
@@ -392,6 +428,42 @@ def test_check_archives_with_repair_passes_through_to_borg():
)
def test_check_archives_with_log_json_and_repair_passes_through_both_to_borg():
config = {'log_json': True}
flexmock(module).should_receive('make_check_name_flags').with_args(
{'repository'},
(),
).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').with_args(
('borg', 'check', '--repair', '--log-json', 'repo'),
output_file=module.DO_NOT_CAPTURE,
environment=None,
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
).once()
module.check_archives(
repository_path='repo',
config=config,
local_borg_version='1.2.3',
check_arguments=flexmock(
progress=None,
repair=True,
only_checks=None,
force=None,
match_archives=None,
max_duration=None,
),
global_arguments=flexmock(),
checks={'repository'},
archive_filter_flags=(),
)
def test_check_archives_with_max_duration_flag_passes_through_to_borg():
config = {}
flexmock(module).should_receive('make_check_name_flags').with_args(
@@ -402,7 +474,7 @@ def test_check_archives_with_max_duration_flag_passes_through_to_borg():
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', 'check', '--max-duration', '33', 'repo'),
('borg', 'check', '--max-duration', '33', '--log-json', 'repo'),
output_file=None,
environment=None,
working_directory=None,
@@ -438,7 +510,7 @@ def test_check_archives_with_max_duration_option_passes_through_to_borg():
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', 'check', '--max-duration', '33', 'repo'),
('borg', 'check', '--max-duration', '33', '--log-json', 'repo'),
output_file=None,
environment=None,
working_directory=None,
@@ -474,9 +546,9 @@ def test_check_archives_with_max_duration_option_and_archives_check_runs_reposit
(),
).and_return(('--repository-only',))
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'check', '--archives-only', 'repo'))
insert_execute_command_mock(('borg', 'check', '--archives-only', '--log-json', 'repo'))
insert_execute_command_mock(
('borg', 'check', '--max-duration', '33', '--repository-only', 'repo'),
('borg', 'check', '--max-duration', '33', '--repository-only', '--log-json', 'repo'),
)
module.check_archives(
@@ -507,9 +579,9 @@ def test_check_archives_with_max_duration_flag_and_archives_check_runs_repositor
(),
).and_return(('--repository-only',))
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'check', '--archives-only', 'repo'))
insert_execute_command_mock(('borg', 'check', '--archives-only', '--log-json', 'repo'))
insert_execute_command_mock(
('borg', 'check', '--max-duration', '33', '--repository-only', 'repo'),
('borg', 'check', '--max-duration', '33', '--repository-only', '--log-json', 'repo'),
)
module.check_archives(
@@ -541,9 +613,11 @@ def test_check_archives_with_max_duration_option_and_data_check_runs_repository_
(),
).and_return(('--repository-only',))
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'check', '--archives-only', '--verify-data', 'repo'))
insert_execute_command_mock(
('borg', 'check', '--max-duration', '33', '--repository-only', 'repo'),
('borg', 'check', '--archives-only', '--verify-data', '--log-json', 'repo')
)
insert_execute_command_mock(
('borg', 'check', '--max-duration', '33', '--repository-only', '--log-json', 'repo'),
)
module.check_archives(
@@ -575,9 +649,11 @@ def test_check_archives_with_max_duration_flag_and_data_check_runs_repository_ch
(),
).and_return(('--repository-only',))
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'check', '--archives-only', '--verify-data', 'repo'))
insert_execute_command_mock(
('borg', 'check', '--max-duration', '33', '--repository-only', 'repo'),
('borg', 'check', '--archives-only', '--verify-data', '--log-json', 'repo')
)
insert_execute_command_mock(
('borg', 'check', '--max-duration', '33', '--repository-only', '--log-json', 'repo'),
)
module.check_archives(
@@ -608,7 +684,7 @@ def test_check_archives_with_max_duration_flag_overrides_max_duration_option():
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', 'check', '--max-duration', '44', 'repo'),
('borg', 'check', '--max-duration', '44', '--log-json', 'repo'),
output_file=None,
environment=None,
working_directory=None,
@@ -647,7 +723,7 @@ def test_check_archives_calls_borg_with_parameters(checks):
config = {}
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', 'repo'))
insert_execute_command_mock(('borg', 'check', '--log-json', 'repo'))
module.check_archives(
repository_path='repo',
@@ -674,7 +750,7 @@ def test_check_archives_with_data_check_implies_archives_check_calls_borg_with_p
(),
).and_return(())
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'check', 'repo'))
insert_execute_command_mock(('borg', 'check', '--log-json', 'repo'))
module.check_archives(
repository_path='repo',
@@ -702,7 +778,7 @@ def test_check_archives_with_log_info_passes_through_to_borg():
).and_return(())
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_logging_mock(logging.INFO)
insert_execute_command_mock(('borg', 'check', '--info', 'repo'))
insert_execute_command_mock(('borg', 'check', '--log-json', '--info', 'repo'))
module.check_archives(
repository_path='repo',
@@ -730,7 +806,7 @@ def test_check_archives_with_log_debug_passes_through_to_borg():
).and_return(())
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_logging_mock(logging.DEBUG)
insert_execute_command_mock(('borg', 'check', '--debug', '--show-rc', 'repo'))
insert_execute_command_mock(('borg', 'check', '--log-json', '--debug', '--show-rc', 'repo'))
module.check_archives(
repository_path='repo',
@@ -755,7 +831,7 @@ def test_check_archives_with_local_path_calls_borg_via_local_path():
config = {}
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(('borg1', 'check', 'repo'))
insert_execute_command_mock(('borg1', 'check', '--log-json', 'repo'))
module.check_archives(
repository_path='repo',
@@ -782,7 +858,9 @@ def test_check_archives_with_exit_codes_calls_borg_using_them():
config = {'borg_exit_codes': borg_exit_codes}
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', 'repo'), borg_exit_codes=borg_exit_codes)
insert_execute_command_mock(
('borg', 'check', '--log-json', 'repo'), borg_exit_codes=borg_exit_codes
)
module.check_archives(
repository_path='repo',
@@ -807,7 +885,7 @@ def test_check_archives_with_remote_path_passes_through_to_borg():
config = {}
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', '--remote-path', 'borg1', 'repo'))
insert_execute_command_mock(('borg', 'check', '--remote-path', 'borg1', '--log-json', 'repo'))
module.check_archives(
repository_path='repo',
@@ -833,32 +911,7 @@ def test_check_archives_with_umask_passes_through_to_borg():
config = {'umask': '077'}
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', '--umask', '077', 'repo'))
module.check_archives(
repository_path='repo',
config=config,
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_log_json_passes_through_to_borg():
checks = {'repository'}
config = {'log_json': True}
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', '--log-json', 'repo'))
insert_execute_command_mock(('borg', 'check', '--umask', '077', '--log-json', 'repo'))
module.check_archives(
repository_path='repo',
@@ -883,7 +936,7 @@ def test_check_archives_with_lock_wait_passes_through_to_borg():
config = {'lock_wait': 5}
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', '--lock-wait', '5', 'repo'))
insert_execute_command_mock(('borg', 'check', '--log-json', '--lock-wait', '5', 'repo'))
module.check_archives(
repository_path='repo',
@@ -909,7 +962,7 @@ def test_check_archives_with_retention_prefix():
config = {'prefix': prefix}
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', 'repo'))
insert_execute_command_mock(('borg', 'check', '--log-json', 'repo'))
module.check_archives(
repository_path='repo',
@@ -937,7 +990,7 @@ def test_check_archives_with_extra_borg_options_passes_through_to_borg():
).and_return(())
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
('borg', 'check', '--extra', '--options', 'value with space', 'repo'),
('borg', 'check', '--log-json', '--extra', '--options', 'value with space', 'repo'),
)
module.check_archives(
@@ -968,7 +1021,7 @@ def test_check_archives_with_match_archives_passes_through_to_borg():
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', 'check', '--match-archives', 'foo-*', 'repo'),
('borg', 'check', '--match-archives', 'foo-*', '--log-json', 'repo'),
output_file=None,
environment=None,
working_directory=None,
@@ -1003,7 +1056,9 @@ def test_check_archives_calls_borg_with_working_directory():
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)
insert_execute_command_mock(('borg', 'check', 'repo'), working_directory='/working/dir')
insert_execute_command_mock(
('borg', 'check', '--log-json', 'repo'), working_directory='/working/dir'
)
module.check_archives(
repository_path='repo',
+39 -25
View File
@@ -32,7 +32,7 @@ COMPACT_COMMAND = ('borg', 'compact')
def test_compact_segments_calls_borg_with_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock((*COMPACT_COMMAND, 'repo'), logging.INFO)
insert_execute_command_mock((*COMPACT_COMMAND, '--log-json', 'repo'), logging.INFO)
module.compact_segments(
dry_run=False,
@@ -45,7 +45,7 @@ def test_compact_segments_calls_borg_with_flags():
def test_compact_segments_with_log_info_calls_borg_with_info_flag():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock((*COMPACT_COMMAND, '--info', 'repo'), logging.INFO)
insert_execute_command_mock((*COMPACT_COMMAND, '--log-json', '--info', 'repo'), logging.INFO)
insert_logging_mock(logging.INFO)
module.compact_segments(
@@ -59,7 +59,9 @@ def test_compact_segments_with_log_info_calls_borg_with_info_flag():
def test_compact_segments_with_log_debug_calls_borg_with_debug_flag():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock((*COMPACT_COMMAND, '--debug', '--show-rc', 'repo'), logging.INFO)
insert_execute_command_mock(
(*COMPACT_COMMAND, '--log-json', '--debug', '--show-rc', 'repo'), logging.INFO
)
insert_logging_mock(logging.DEBUG)
module.compact_segments(
@@ -112,7 +114,7 @@ def test_compact_segments_with_dry_run_executes_borg_call_when_feature_available
def test_compact_segments_with_local_path_calls_borg_via_local_path():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg1', *COMPACT_COMMAND[1:], 'repo'), logging.INFO)
insert_execute_command_mock(('borg1', *COMPACT_COMMAND[1:], '--log-json', 'repo'), logging.INFO)
module.compact_segments(
dry_run=False,
@@ -128,7 +130,7 @@ def test_compact_segments_with_exit_codes_calls_borg_using_them():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
borg_exit_codes = flexmock()
insert_execute_command_mock(
(*COMPACT_COMMAND, 'repo'),
(*COMPACT_COMMAND, '--log-json', 'repo'),
logging.INFO,
borg_exit_codes=borg_exit_codes,
)
@@ -144,7 +146,9 @@ def test_compact_segments_with_exit_codes_calls_borg_using_them():
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', 'repo'), logging.INFO)
insert_execute_command_mock(
(*COMPACT_COMMAND, '--remote-path', 'borg1', '--log-json', 'repo'), logging.INFO
)
module.compact_segments(
dry_run=False,
@@ -169,9 +173,26 @@ def test_compact_segments_with_progress_calls_borg_with_progress_flag():
)
def test_compact_segments_with_log_json_and_progress_calls_borg_with_both_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
(*COMPACT_COMMAND, '--log-json', '--progress', 'repo'), logging.INFO
)
module.compact_segments(
dry_run=False,
repository_path='repo',
config={'log_json': True, 'progress': True},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
def test_compact_segments_with_cleanup_commits_calls_borg_with_cleanup_commits_flag():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock((*COMPACT_COMMAND, '--cleanup-commits', 'repo'), logging.INFO)
insert_execute_command_mock(
(*COMPACT_COMMAND, '--log-json', '--cleanup-commits', 'repo'), logging.INFO
)
module.compact_segments(
dry_run=False,
@@ -185,7 +206,9 @@ def test_compact_segments_with_cleanup_commits_calls_borg_with_cleanup_commits_f
def test_compact_segments_with_threshold_calls_borg_with_threshold_flag():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock((*COMPACT_COMMAND, '--threshold', '20', 'repo'), logging.INFO)
insert_execute_command_mock(
(*COMPACT_COMMAND, '--log-json', '--threshold', '20', 'repo'), logging.INFO
)
module.compact_segments(
dry_run=False,
@@ -199,7 +222,9 @@ def test_compact_segments_with_threshold_calls_borg_with_threshold_flag():
def test_compact_segments_with_umask_calls_borg_with_umask_flags():
config = {'umask': '077'}
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock((*COMPACT_COMMAND, '--umask', '077', 'repo'), logging.INFO)
insert_execute_command_mock(
(*COMPACT_COMMAND, '--umask', '077', '--log-json', 'repo'), logging.INFO
)
module.compact_segments(
dry_run=False,
@@ -210,23 +235,12 @@ def test_compact_segments_with_umask_calls_borg_with_umask_flags():
)
def test_compact_segments_with_log_json_calls_borg_with_log_json_flags():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock((*COMPACT_COMMAND, '--log-json', 'repo'), logging.INFO)
module.compact_segments(
dry_run=False,
repository_path='repo',
config={'log_json': True},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
def test_compact_segments_with_lock_wait_calls_borg_with_lock_wait_flags():
config = {'lock_wait': 5}
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock((*COMPACT_COMMAND, '--lock-wait', '5', 'repo'), logging.INFO)
insert_execute_command_mock(
(*COMPACT_COMMAND, '--log-json', '--lock-wait', '5', 'repo'), logging.INFO
)
module.compact_segments(
dry_run=False,
@@ -240,7 +254,7 @@ def test_compact_segments_with_lock_wait_calls_borg_with_lock_wait_flags():
def test_compact_segments_with_extra_borg_options_calls_borg_with_extra_options():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
(*COMPACT_COMMAND, '--extra', '--options', 'value with space', 'repo'),
(*COMPACT_COMMAND, '--log-json', '--extra', '--options', 'value with space', 'repo'),
logging.INFO,
)
@@ -256,7 +270,7 @@ def test_compact_segments_with_extra_borg_options_calls_borg_with_extra_options(
def test_compact_segments_calls_borg_with_working_directory():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(
(*COMPACT_COMMAND, 'repo'),
(*COMPACT_COMMAND, '--log-json', 'repo'),
logging.INFO,
working_directory='/working/dir',
)
+108 -51
View File
@@ -283,7 +283,7 @@ def test_make_base_create_produces_borg_command():
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create')
assert create_flags == ('borg', 'create', '--log-json')
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
@@ -320,7 +320,7 @@ def test_make_base_create_command_includes_patterns_file_in_borg_command():
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create', *pattern_flags)
assert create_flags == ('borg', 'create', *pattern_flags, '--log-json')
assert create_positional_arguments == (f'repo::{DEFAULT_ARCHIVE_NAME}',)
assert pattern_file == mock_pattern_file
@@ -353,7 +353,7 @@ def test_make_base_create_command_with_store_config_false_omits_config_files():
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create')
assert create_flags == ('borg', 'create', '--log-json')
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
@@ -422,7 +422,76 @@ def test_make_base_create_command_includes_configuration_option_as_command_flag(
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create', *option_flags)
assert create_flags == ('borg', 'create', *option_flags, '--log-json')
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
def test_make_base_create_command_with_progress_omits_log_json_from_borg_command():
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(None)
flexmock(module.borgmatic.borg.flags).should_receive('make_list_filter_flags').and_return('FOO')
flexmock(module.flags).should_receive('get_default_archive_name_format').and_return(
'{hostname}',
)
flexmock(module.feature).should_receive('available').and_return(True)
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('validate_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
repository_path='repo',
config={
'source_directories': ['foo', 'bar'],
'repositories': ['repo'],
'exclude_patterns': ['exclude'],
'progress': True,
},
patterns=[Pattern('foo'), Pattern('bar')],
local_borg_version='1.2.3',
global_arguments=flexmock(),
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create')
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
def test_make_base_create_command_with_log_json_and_progress_includes_log_json_in_borg_command():
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(None)
flexmock(module.borgmatic.borg.flags).should_receive('make_list_filter_flags').and_return('FOO')
flexmock(module.flags).should_receive('get_default_archive_name_format').and_return(
'{hostname}',
)
flexmock(module.feature).should_receive('available').and_return(True)
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('validate_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
repository_path='repo',
config={
'source_directories': ['foo', 'bar'],
'repositories': ['repo'],
'exclude_patterns': ['exclude'],
'log_json': True,
'progress': True,
},
patterns=[Pattern('foo'), Pattern('bar')],
local_borg_version='1.2.3',
global_arguments=flexmock(),
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create', '--log-json')
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
@@ -455,7 +524,7 @@ def test_make_base_create_command_includes_dry_run_in_borg_command():
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create', '--dry-run')
assert create_flags == ('borg', 'create', '--log-json', '--dry-run')
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
@@ -489,7 +558,7 @@ def test_make_base_create_command_includes_comment_in_borg_command():
comment='a comment',
)
assert create_flags == ('borg', 'create', '--comment', 'a comment')
assert create_flags == ('borg', 'create', '--comment', 'a comment', '--log-json')
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
@@ -522,7 +591,7 @@ def test_make_base_create_command_includes_local_path_in_borg_command():
local_path='borg1',
)
assert create_flags == ('borg1', 'create')
assert create_flags == ('borg1', 'create', '--log-json')
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
@@ -555,40 +624,7 @@ def test_make_base_create_command_includes_remote_path_in_borg_command():
remote_path='borg1',
)
assert create_flags == ('borg', 'create', '--remote-path', 'borg1')
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
def test_make_base_create_command_includes_log_json_in_borg_command():
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(None)
flexmock(module.borgmatic.borg.flags).should_receive('make_list_filter_flags').and_return('FOO')
flexmock(module.flags).should_receive('get_default_archive_name_format').and_return(
'{hostname}',
)
flexmock(module.feature).should_receive('available').and_return(True)
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
)
flexmock(module).should_receive('validate_planned_backup_paths').and_return(())
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
dry_run=False,
repository_path='repo',
config={
'source_directories': ['foo', 'bar'],
'repositories': ['repo'],
'log_json': True,
},
patterns=[Pattern('foo'), Pattern('bar')],
local_borg_version='1.2.3',
global_arguments=flexmock(),
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create', '--log-json')
assert create_flags == ('borg', 'create', '--remote-path', 'borg1', '--log-json')
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
@@ -621,7 +657,7 @@ def test_make_base_create_command_includes_list_flags_in_borg_command():
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create', '--list', '--filter', 'FOO')
assert create_flags == ('borg', 'create', '--log-json', '--list', '--filter', 'FOO')
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
@@ -686,7 +722,14 @@ def test_make_base_create_command_with_stream_processes_ignores_read_special_fal
stream_processes=flexmock(),
)
assert create_flags == ('borg', 'create', '--patterns-from', 'patterns', '--read-special')
assert create_flags == (
'borg',
'create',
'--patterns-from',
'patterns',
'--read-special',
'--log-json',
)
assert create_positional_arguments == REPO_ARCHIVE
assert pattern_file
@@ -749,7 +792,14 @@ def test_make_base_create_command_without_patterns_and_with_stream_processes_ign
stream_processes=flexmock(),
)
assert create_flags == ('borg', 'create', '--read-special', '--patterns-from', 'patterns')
assert create_flags == (
'borg',
'create',
'--read-special',
'--log-json',
'--patterns-from',
'patterns',
)
assert create_positional_arguments == REPO_ARCHIVE
assert pattern_file
@@ -784,7 +834,7 @@ def test_make_base_create_command_with_stream_processes_and_read_special_true_sk
stream_processes=flexmock(),
)
assert create_flags == ('borg', 'create', '--read-special')
assert create_flags == ('borg', 'create', '--read-special', '--log-json')
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
@@ -817,7 +867,7 @@ def test_make_base_create_command_includes_archive_name_format_in_borg_command()
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create')
assert create_flags == ('borg', 'create', '--log-json')
assert create_positional_arguments == ('repo::ARCHIVE_NAME',)
assert not pattern_file
@@ -849,7 +899,7 @@ def test_make_base_create_command_includes_default_archive_name_format_in_borg_c
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create')
assert create_flags == ('borg', 'create', '--log-json')
assert create_positional_arguments == ('repo::{hostname}',)
assert not pattern_file
@@ -882,7 +932,7 @@ def test_make_base_create_command_includes_archive_name_format_with_placeholders
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create')
assert create_flags == ('borg', 'create', '--log-json')
assert create_positional_arguments == (repository_archive_pattern,)
assert not pattern_file
@@ -915,7 +965,7 @@ def test_make_base_create_command_includes_repository_and_archive_name_format_wi
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create')
assert create_flags == ('borg', 'create', '--log-json')
assert create_positional_arguments == (repository_archive_pattern,)
assert not pattern_file
@@ -944,7 +994,7 @@ def test_make_base_create_command_includes_archive_suffix_in_borg_command():
archive_suffix='.checkpoint',
)
assert create_flags == ('borg', 'create')
assert create_flags == ('borg', 'create', '--log-json')
assert create_positional_arguments == (f'repo::{DEFAULT_ARCHIVE_NAME}.checkpoint',)
assert not pattern_file
@@ -977,7 +1027,14 @@ def test_make_base_create_command_includes_extra_borg_options_in_borg_command():
borgmatic_runtime_directory='/run/borgmatic',
)
assert create_flags == ('borg', 'create', '--extra', '--options', 'value with space')
assert create_flags == (
'borg',
'create',
'--log-json',
'--extra',
'--options',
'value with space',
)
assert create_positional_arguments == REPO_ARCHIVE
assert not pattern_file
+12 -37
View File
@@ -27,7 +27,7 @@ def test_make_delete_command_includes_log_info():
remote_path=None,
)
assert command == ('borg', 'delete', '--info', 'repo')
assert command == ('borg', 'delete', '--info', '--log-json', 'repo')
def test_make_delete_command_includes_log_debug():
@@ -49,7 +49,7 @@ def test_make_delete_command_includes_log_debug():
remote_path=None,
)
assert command == ('borg', 'delete', '--debug', '--show-rc', 'repo')
assert command == ('borg', 'delete', '--debug', '--show-rc', '--log-json', 'repo')
def test_make_delete_command_includes_dry_run():
@@ -74,7 +74,7 @@ def test_make_delete_command_includes_dry_run():
remote_path=None,
)
assert command == ('borg', 'delete', '--dry-run', 'repo')
assert command == ('borg', 'delete', '--dry-run', '--log-json', 'repo')
def test_make_delete_command_includes_remote_path():
@@ -99,7 +99,7 @@ def test_make_delete_command_includes_remote_path():
remote_path='borg1',
)
assert command == ('borg', 'delete', '--remote-path', 'borg1', 'repo')
assert command == ('borg', 'delete', '--remote-path', 'borg1', '--log-json', 'repo')
def test_make_delete_command_includes_umask():
@@ -122,32 +122,7 @@ def test_make_delete_command_includes_umask():
remote_path=None,
)
assert command == ('borg', 'delete', '--umask', '077', 'repo')
def test_make_delete_command_includes_log_json():
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
'log-json',
True,
).and_return(('--log-json',))
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',),
)
command = module.make_delete_command(
repository={'path': 'repo'},
config={'log_json': True},
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=None,
)
assert command == ('borg', 'delete', '--log-json', 'repo')
assert command == ('borg', 'delete', '--umask', '077', '--log-json', 'repo')
def test_make_delete_command_includes_lock_wait():
@@ -172,7 +147,7 @@ def test_make_delete_command_includes_lock_wait():
remote_path=None,
)
assert command == ('borg', 'delete', '--lock-wait', '5', 'repo')
assert command == ('borg', 'delete', '--log-json', '--lock-wait', '5', 'repo')
def test_make_delete_command_includes_extra_borg_options():
@@ -193,7 +168,7 @@ def test_make_delete_command_includes_extra_borg_options():
remote_path=None,
)
assert command == ('borg', 'delete', '--extra', 'value with space', 'repo')
assert command == ('borg', 'delete', '--log-json', '--extra', 'value with space', 'repo')
def test_make_delete_command_with_list_config_calls_borg_with_list_flag():
@@ -218,7 +193,7 @@ def test_make_delete_command_with_list_config_calls_borg_with_list_flag():
remote_path=None,
)
assert command == ('borg', 'delete', '--list', 'repo')
assert command == ('borg', 'delete', '--log-json', '--list', 'repo')
def test_make_delete_command_includes_force():
@@ -239,7 +214,7 @@ def test_make_delete_command_includes_force():
remote_path=None,
)
assert command == ('borg', 'delete', '--force', 'repo')
assert command == ('borg', 'delete', '--log-json', '--force', 'repo')
def test_make_delete_command_includes_force_twice():
@@ -260,7 +235,7 @@ def test_make_delete_command_includes_force_twice():
remote_path=None,
)
assert command == ('borg', 'delete', '--force', '--force', 'repo')
assert command == ('borg', 'delete', '--log-json', '--force', '--force', 'repo')
def test_make_delete_command_includes_archive():
@@ -288,7 +263,7 @@ def test_make_delete_command_includes_archive():
remote_path=None,
)
assert command == ('borg', 'delete', '--match-archives', 'archive', 'repo')
assert command == ('borg', 'delete', '--log-json', '--match-archives', 'archive', 'repo')
def test_make_delete_command_includes_match_archives():
@@ -316,7 +291,7 @@ def test_make_delete_command_includes_match_archives():
remote_path=None,
)
assert command == ('borg', 'delete', '--match-archives', 'sh:foo*', 'repo')
assert command == ('borg', 'delete', '--log-json', '--match-archives', 'sh:foo*', 'repo')
LOGGING_ANSWER = flexmock()
+28 -30
View File
@@ -35,7 +35,7 @@ def insert_execute_command_mock(
def test_export_key_calls_borg_with_required_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', 'repo'))
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', 'repo'))
module.export_key(
repository_path='repo',
@@ -49,7 +49,7 @@ def test_export_key_calls_borg_with_required_flags():
def test_export_key_calls_borg_with_local_path():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
flexmock(module.os.path).should_receive('exists').never()
insert_execute_command_mock(('borg1', 'key', 'export', 'repo'))
insert_execute_command_mock(('borg1', 'key', 'export', '--log-json', 'repo'))
module.export_key(
repository_path='repo',
@@ -65,7 +65,9 @@ def test_export_key_calls_borg_using_exit_codes():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
flexmock(module.os.path).should_receive('exists').never()
borg_exit_codes = flexmock()
insert_execute_command_mock(('borg', 'key', 'export', 'repo'), borg_exit_codes=borg_exit_codes)
insert_execute_command_mock(
('borg', 'key', 'export', '--log-json', 'repo'), borg_exit_codes=borg_exit_codes
)
module.export_key(
repository_path='repo',
@@ -79,7 +81,9 @@ def test_export_key_calls_borg_using_exit_codes():
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()
insert_execute_command_mock(('borg', 'key', 'export', '--remote-path', 'borg1', 'repo'))
insert_execute_command_mock(
('borg', 'key', 'export', '--remote-path', 'borg1', '--log-json', 'repo')
)
module.export_key(
repository_path='repo',
@@ -94,7 +98,7 @@ def test_export_key_calls_borg_with_remote_path_flags():
def test_export_key_calls_borg_with_umask_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', '--umask', '0770', 'repo'))
insert_execute_command_mock(('borg', 'key', 'export', '--umask', '0770', '--log-json', 'repo'))
module.export_key(
repository_path='repo',
@@ -105,24 +109,10 @@ def test_export_key_calls_borg_with_umask_flags():
)
def test_export_key_calls_borg_with_log_json_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', '--log-json', 'repo'))
module.export_key(
repository_path='repo',
config={'log_json': True},
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_lock_wait_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', '--lock-wait', '5', 'repo'))
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', '--lock-wait', '5', 'repo'))
module.export_key(
repository_path='repo',
@@ -136,7 +126,9 @@ def test_export_key_calls_borg_with_lock_wait_flags():
def test_export_key_calls_borg_with_extra_borg_options():
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', '--extra', 'value with space', 'repo'))
insert_execute_command_mock(
('borg', 'key', 'export', '--log-json', '--extra', 'value with space', 'repo')
)
module.export_key(
repository_path='repo',
@@ -150,7 +142,7 @@ def test_export_key_calls_borg_with_extra_borg_options():
def test_export_key_with_log_info_calls_borg_with_info_parameter():
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', '--info', 'repo'))
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', '--info', 'repo'))
insert_logging_mock(logging.INFO)
module.export_key(
@@ -165,7 +157,9 @@ def test_export_key_with_log_info_calls_borg_with_info_parameter():
def test_export_key_with_log_debug_calls_borg_with_debug_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', '--debug', '--show-rc', 'repo'))
insert_execute_command_mock(
('borg', 'key', 'export', '--log-json', '--debug', '--show-rc', 'repo')
)
insert_logging_mock(logging.DEBUG)
module.export_key(
@@ -180,7 +174,7 @@ def test_export_key_with_log_debug_calls_borg_with_debug_flags():
def test_export_key_calls_borg_with_paper_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', '--paper', 'repo'))
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', '--paper', 'repo'))
module.export_key(
repository_path='repo',
@@ -194,7 +188,7 @@ def test_export_key_calls_borg_with_paper_flags():
def test_export_key_calls_borg_with_paper_flag():
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', '--paper', 'repo'))
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', '--paper', 'repo'))
module.export_key(
repository_path='repo',
@@ -208,7 +202,7 @@ def test_export_key_calls_borg_with_paper_flag():
def test_export_key_calls_borg_with_qr_html_flag():
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', '--qr-html', 'repo'))
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', '--qr-html', 'repo'))
module.export_key(
repository_path='repo',
@@ -222,7 +216,9 @@ def test_export_key_calls_borg_with_qr_html_flag():
def test_export_key_calls_borg_with_path_argument():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
flexmock(module.os.path).should_receive('exists').with_args('dest').and_return(False)
insert_execute_command_mock(('borg', 'key', 'export', 'repo', 'dest'), output_file=None)
insert_execute_command_mock(
('borg', 'key', 'export', '--log-json', 'repo', 'dest'), output_file=None
)
module.export_key(
repository_path='repo',
@@ -251,7 +247,7 @@ def test_export_key_with_already_existent_path_raises():
def test_export_key_with_stdout_path_calls_borg_without_path_argument():
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', 'repo'))
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', 'repo'))
module.export_key(
repository_path='repo',
@@ -279,7 +275,9 @@ def test_export_key_with_dry_run_skips_borg_call():
def test_export_key_calls_borg_with_working_directory():
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', 'repo'), working_directory='/working/dir')
insert_execute_command_mock(
('borg', 'key', 'export', '--log-json', 'repo'), working_directory='/working/dir'
)
module.export_key(
repository_path='repo',
@@ -296,7 +294,7 @@ def test_export_key_calls_borg_with_path_argument_and_working_directory():
False,
).once()
insert_execute_command_mock(
('borg', 'key', 'export', 'repo', 'dest'),
('borg', 'key', 'export', '--log-json', 'repo', 'dest'),
output_file=None,
working_directory='/working/dir',
)
+37 -35
View File
@@ -37,7 +37,7 @@ def test_export_tar_archive_calls_borg_with_path_flags():
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'export-tar', 'repo::archive', 'test.tar', 'path1', 'path2'),
('borg', 'export-tar', '--log-json', 'repo::archive', 'test.tar', 'path1', 'path2'),
)
module.export_tar_archive(
@@ -59,7 +59,7 @@ def test_export_tar_archive_calls_borg_with_local_path_flags():
('repo::archive',),
)
insert_execute_command_mock(
('borg1', 'export-tar', 'repo::archive', 'test.tar'),
('borg1', 'export-tar', '--log-json', 'repo::archive', 'test.tar'),
borg_local_path='borg1',
)
@@ -84,7 +84,7 @@ def test_export_tar_archive_calls_borg_using_exit_codes():
)
borg_exit_codes = flexmock()
insert_execute_command_mock(
('borg', 'export-tar', 'repo::archive', 'test.tar'),
('borg', 'export-tar', '--log-json', 'repo::archive', 'test.tar'),
borg_exit_codes=borg_exit_codes,
)
@@ -107,7 +107,7 @@ def test_export_tar_archive_calls_borg_with_remote_path_flags():
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'export-tar', '--remote-path', 'borg1', 'repo::archive', 'test.tar'),
('borg', 'export-tar', '--remote-path', 'borg1', '--log-json', 'repo::archive', 'test.tar'),
)
module.export_tar_archive(
@@ -130,7 +130,7 @@ def test_export_tar_archive_calls_borg_with_umask_flags():
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'export-tar', '--umask', '0770', 'repo::archive', 'test.tar'),
('borg', 'export-tar', '--umask', '0770', '--log-json', 'repo::archive', 'test.tar'),
)
module.export_tar_archive(
@@ -145,26 +145,6 @@ def test_export_tar_archive_calls_borg_with_umask_flags():
)
def test_export_tar_archive_calls_borg_with_log_json_flag():
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', '--log-json', 'repo::archive', 'test.tar'))
module.export_tar_archive(
dry_run=False,
repository_path='repo',
archive='archive',
paths=None,
destination_path='test.tar',
config={'log_json': True},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
def test_export_tar_archive_calls_borg_with_lock_wait_flags():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
@@ -172,7 +152,7 @@ def test_export_tar_archive_calls_borg_with_lock_wait_flags():
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'export-tar', '--lock-wait', '5', 'repo::archive', 'test.tar'),
('borg', 'export-tar', '--log-json', '--lock-wait', '5', 'repo::archive', 'test.tar'),
)
module.export_tar_archive(
@@ -194,7 +174,15 @@ def test_export_tar_archive_calls_borg_with_extra_borg_options():
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'export-tar', '--extra', 'value with space', 'repo::archive', 'test.tar'),
(
'borg',
'export-tar',
'--log-json',
'--extra',
'value with space',
'repo::archive',
'test.tar',
),
)
module.export_tar_archive(
@@ -215,7 +203,9 @@ def test_export_tar_archive_with_log_info_calls_borg_with_info_flag():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
insert_execute_command_mock(('borg', 'export-tar', '--info', 'repo::archive', 'test.tar'))
insert_execute_command_mock(
('borg', 'export-tar', '--log-json', '--info', 'repo::archive', 'test.tar')
)
insert_logging_mock(logging.INFO)
module.export_tar_archive(
@@ -237,7 +227,7 @@ def test_export_tar_archive_with_log_debug_calls_borg_with_debug_flags():
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'export-tar', '--debug', '--show-rc', 'repo::archive', 'test.tar'),
('borg', 'export-tar', '--log-json', '--debug', '--show-rc', 'repo::archive', 'test.tar'),
)
insert_logging_mock(logging.DEBUG)
@@ -280,7 +270,7 @@ def test_export_tar_archive_calls_borg_with_tar_filter_flags():
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'export-tar', '--tar-filter', 'bzip2', 'repo::archive', 'test.tar'),
('borg', 'export-tar', '--log-json', '--tar-filter', 'bzip2', 'repo::archive', 'test.tar'),
)
module.export_tar_archive(
@@ -303,7 +293,7 @@ def test_export_tar_archive_calls_borg_with_list_flag():
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'export-tar', '--list', 'repo::archive', 'test.tar'),
('borg', 'export-tar', '--log-json', '--list', 'repo::archive', 'test.tar'),
output_log_level=logging.ANSWER,
)
@@ -326,7 +316,15 @@ def test_export_tar_archive_calls_borg_with_strip_components_flag():
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'export-tar', '--strip-components', '5', 'repo::archive', 'test.tar'),
(
'borg',
'export-tar',
'--log-json',
'--strip-components',
'5',
'repo::archive',
'test.tar',
),
)
module.export_tar_archive(
@@ -348,7 +346,9 @@ def test_export_tar_archive_skips_abspath_for_remote_repository_flag():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('server:repo::archive',),
)
insert_execute_command_mock(('borg', 'export-tar', 'server:repo::archive', 'test.tar'))
insert_execute_command_mock(
('borg', 'export-tar', '--log-json', 'server:repo::archive', 'test.tar')
)
module.export_tar_archive(
dry_run=False,
@@ -368,7 +368,9 @@ def test_export_tar_archive_calls_borg_with_stdout_destination_path():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
insert_execute_command_mock(('borg', 'export-tar', 'repo::archive', '-'), capture=False)
insert_execute_command_mock(
('borg', 'export-tar', '--log-json', 'repo::archive', '-'), capture=False
)
module.export_tar_archive(
dry_run=False,
@@ -389,7 +391,7 @@ def test_export_tar_archive_calls_borg_with_working_directory():
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'export-tar', 'repo::archive', 'test.tar'),
('borg', 'export-tar', '--log-json', 'repo::archive', 'test.tar'),
working_directory='/working/dir',
)
+92 -61
View File
@@ -21,7 +21,7 @@ def insert_execute_command_mock(command, destination_path=None, borg_exit_codes=
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'))
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',),
)
@@ -50,7 +50,9 @@ def test_extract_last_archive_dry_run_without_any_archives_should_not_raise():
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_execute_command_mock(
('borg', 'extract', '--dry-run', '--log-json', '--info', 'repo::archive')
)
insert_logging_mock(logging.INFO)
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
@@ -68,7 +70,16 @@ def test_extract_last_archive_dry_run_with_log_info_calls_borg_with_info_paramet
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'),
(
'borg',
'extract',
'--dry-run',
'--log-json',
'--debug',
'--show-rc',
'--list',
'repo::archive',
),
)
insert_logging_mock(logging.DEBUG)
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
@@ -86,7 +97,7 @@ 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():
flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
insert_execute_command_mock(('borg1', 'extract', '--dry-run', 'repo::archive'))
insert_execute_command_mock(('borg1', 'extract', '--dry-run', '--log-json', 'repo::archive'))
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
@@ -105,7 +116,7 @@ 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', 'extract', '--dry-run', '--log-json', 'repo::archive'),
borg_exit_codes=borg_exit_codes,
)
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
@@ -124,7 +135,7 @@ def test_extract_last_archive_dry_run_calls_borg_using_exit_codes():
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'),
('borg', 'extract', '--dry-run', '--remote-path', 'borg1', '--log-json', 'repo::archive'),
)
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
@@ -140,26 +151,10 @@ def test_extract_last_archive_dry_run_calls_borg_with_remote_path_flags():
)
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={'log_json': True},
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_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'),
('borg', 'extract', '--dry-run', '--log-json', '--lock-wait', '5', 'repo::archive'),
)
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
@@ -177,7 +172,15 @@ def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_flags():
def test_extract_last_archive_dry_run_calls_borg_with_extra_borg_options():
flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
insert_execute_command_mock(
('borg', 'extract', '--dry-run', '--extra', 'value with space', 'repo::archive'),
(
'borg',
'extract',
'--dry-run',
'--log-json',
'--extra',
'value with space',
'repo::archive',
),
)
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
@@ -193,7 +196,9 @@ def test_extract_last_archive_dry_run_calls_borg_with_extra_borg_options():
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'))
insert_execute_command_mock(
('borg', 'extract', '--log-json', '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(
@@ -216,7 +221,7 @@ def test_extract_archive_calls_borg_with_path_flags():
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'))
insert_execute_command_mock(('borg1', '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(
@@ -242,7 +247,7 @@ 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', 'extract', '--log-json', 'repo::archive'),
borg_exit_codes=borg_exit_codes,
)
flexmock(module.feature).should_receive('available').and_return(True)
@@ -267,7 +272,9 @@ def test_extract_archive_calls_borg_with_exit_codes():
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'))
insert_execute_command_mock(
('borg', 'extract', '--remote-path', 'borg1', '--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(
@@ -298,7 +305,7 @@ def test_extract_archive_calls_borg_with_remote_path_flags():
)
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'))
insert_execute_command_mock(('borg', 'extract', option_flag, '--log-json', '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(
@@ -321,7 +328,9 @@ def test_extract_archive_calls_borg_with_numeric_ids_parameter(feature_available
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'))
insert_execute_command_mock(
('borg', 'extract', '--umask', '0770', '--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(
@@ -342,29 +351,11 @@ def test_extract_archive_calls_borg_with_umask_flags():
)
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={'log_json': True},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
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'))
insert_execute_command_mock(
('borg', 'extract', '--log-json', '--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(
@@ -387,7 +378,9 @@ def test_extract_archive_calls_borg_with_lock_wait_flags():
def test_extract_archive_calls_borg_with_extra_borg_options():
flexmock(module.os.path).should_receive('abspath').and_return('repo')
insert_execute_command_mock(('borg', 'extract', '--extra', 'value with space', 'repo::archive'))
insert_execute_command_mock(
('borg', 'extract', '--log-json', '--extra', 'value with space', '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(
@@ -410,7 +403,7 @@ def test_extract_archive_calls_borg_with_extra_borg_options():
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_execute_command_mock(('borg', 'extract', '--log-json', '--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)
@@ -435,7 +428,7 @@ def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
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'),
('borg', 'extract', '--log-json', '--debug', '--list', '--show-rc', 'repo::archive'),
)
insert_logging_mock(logging.DEBUG)
flexmock(module.feature).should_receive('available').and_return(True)
@@ -460,7 +453,7 @@ def test_extract_archive_with_log_debug_calls_borg_with_debug_flags():
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'))
insert_execute_command_mock(('borg', 'extract', '--log-json', '--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(
@@ -483,7 +476,9 @@ def test_extract_archive_calls_borg_with_dry_run_parameter():
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')
insert_execute_command_mock(
('borg', 'extract', '--log-json', '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(
@@ -507,7 +502,9 @@ def test_extract_archive_calls_borg_with_destination_path():
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'))
insert_execute_command_mock(
('borg', 'extract', '--log-json', '--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(
@@ -535,6 +532,7 @@ def test_extract_archive_calls_borg_with_strip_components_calculated_from_all():
(
'borg',
'extract',
'--log-json',
'--strip-components',
'2',
'repo::archive',
@@ -569,6 +567,7 @@ def test_extract_archive_calls_borg_with_strip_components_calculated_from_all_wi
(
'borg',
'extract',
'--log-json',
'--strip-components',
'2',
'repo::archive',
@@ -654,6 +653,38 @@ def test_extract_archive_calls_borg_with_progress_flag():
)
def test_extract_archive_with_log_json_and_progress_calls_borg_with_both_flags():
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', '--log-json', '--progress', 'repo::archive'),
output_file=module.DO_NOT_CAPTURE,
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={'log_json': True, 'progress': True},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
def test_extract_archive_with_progress_and_extract_to_stdout_raises():
flexmock(module).should_receive('execute_command').never()
@@ -676,7 +707,7 @@ def test_extract_archive_calls_borg_with_stdout_parameter_and_returns_process():
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'),
('borg', 'extract', '--log-json', '--stdout', 'repo::archive'),
output_file=module.subprocess.PIPE,
run_to_completion=False,
environment=None,
@@ -713,7 +744,7 @@ def test_extract_archive_skips_abspath_for_remote_repository():
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'),
('borg', 'extract', '--log-json', 'server:repo::archive'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -742,7 +773,7 @@ def test_extract_archive_skips_abspath_for_remote_repository():
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'),
('borg', 'extract', '--log-json', '/working/dir/repo::archive'),
destination_path='/working/dir/dest',
)
flexmock(module.feature).should_receive('available').and_return(True)
@@ -767,7 +798,7 @@ def test_extract_archive_uses_configured_working_directory_in_repo_path_and_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'))
insert_execute_command_mock(('borg', 'extract', '--log-json', '/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',),
+26 -29
View File
@@ -33,7 +33,7 @@ def test_import_key_calls_borg_with_required_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', 'repo'))
insert_execute_command_mock(('borg', 'key', 'import', '--log-json', 'repo'))
module.import_key(
repository_path='repo',
@@ -48,7 +48,7 @@ def test_import_key_calls_borg_with_local_path():
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(('borg1', 'key', 'import', 'repo'))
insert_execute_command_mock(('borg1', 'key', 'import', '--log-json', 'repo'))
module.import_key(
repository_path='repo',
@@ -65,7 +65,9 @@ def test_import_key_calls_borg_using_exit_codes():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
flexmock(module.os.path).should_receive('exists').never()
borg_exit_codes = flexmock()
insert_execute_command_mock(('borg', 'key', 'import', 'repo'), borg_exit_codes=borg_exit_codes)
insert_execute_command_mock(
('borg', 'key', 'import', '--log-json', 'repo'), borg_exit_codes=borg_exit_codes
)
module.import_key(
repository_path='repo',
@@ -80,7 +82,9 @@ 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',))
flexmock(module.os.path).should_receive('exists').never()
insert_execute_command_mock(('borg', 'key', 'import', '--remote-path', 'borg1', 'repo'))
insert_execute_command_mock(
('borg', 'key', 'import', '--remote-path', 'borg1', '--log-json', 'repo')
)
module.import_key(
repository_path='repo',
@@ -96,7 +100,7 @@ def test_import_key_calls_borg_with_umask_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', '--umask', '0770', 'repo'))
insert_execute_command_mock(('borg', 'key', 'import', '--umask', '0770', '--log-json', 'repo'))
module.import_key(
repository_path='repo',
@@ -107,26 +111,11 @@ def test_import_key_calls_borg_with_umask_flags():
)
def test_import_key_calls_borg_with_log_json_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', '--log-json', 'repo'))
module.import_key(
repository_path='repo',
config={'log_json': True},
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_lock_wait_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', '--lock-wait', '5', 'repo'))
insert_execute_command_mock(('borg', 'key', 'import', '--log-json', '--lock-wait', '5', 'repo'))
module.import_key(
repository_path='repo',
@@ -141,7 +130,9 @@ def test_import_key_calls_borg_with_extra_borg_options():
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', '--extra', 'value with space', 'repo'))
insert_execute_command_mock(
('borg', 'key', 'import', '--log-json', '--extra', 'value with space', 'repo')
)
module.import_key(
repository_path='repo',
@@ -156,7 +147,7 @@ def test_import_key_with_log_info_calls_borg_with_info_parameter():
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', '--info', 'repo'))
insert_execute_command_mock(('borg', 'key', 'import', '--log-json', '--info', 'repo'))
insert_logging_mock(logging.INFO)
module.import_key(
@@ -172,7 +163,9 @@ def test_import_key_with_log_debug_calls_borg_with_debug_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', '--debug', '--show-rc', 'repo'))
insert_execute_command_mock(
('borg', 'key', 'import', '--log-json', '--debug', '--show-rc', 'repo')
)
insert_logging_mock(logging.DEBUG)
module.import_key(
@@ -188,7 +181,7 @@ def test_import_key_calls_borg_with_paper_flags():
flexmock(module.flags).should_receive('make_flags').and_return(('--paper',))
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', '--paper', 'repo'))
insert_execute_command_mock(('borg', 'key', 'import', '--log-json', '--paper', 'repo'))
module.import_key(
repository_path='repo',
@@ -203,7 +196,9 @@ def test_import_key_calls_borg_with_path_argument():
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').with_args('source').and_return(True)
insert_execute_command_mock(('borg', 'key', 'import', 'repo', 'source'), input_file=None)
insert_execute_command_mock(
('borg', 'key', 'import', '--log-json', 'repo', 'source'), input_file=None
)
module.import_key(
repository_path='repo',
@@ -234,7 +229,7 @@ def test_import_key_with_stdin_path_calls_borg_without_path_argument():
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', 'repo'))
insert_execute_command_mock(('borg', 'key', 'import', '--log-json', 'repo'))
module.import_key(
repository_path='repo',
@@ -264,7 +259,9 @@ def test_import_key_calls_borg_with_working_directory():
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', 'repo'), working_directory='/working/dir')
insert_execute_command_mock(
('borg', 'key', 'import', '--log-json', 'repo'), working_directory='/working/dir'
)
module.import_key(
repository_path='repo',
@@ -282,7 +279,7 @@ def test_import_key_calls_borg_with_path_argument_and_working_directory():
True,
).once()
insert_execute_command_mock(
('borg', 'key', 'import', 'repo', 'source'),
('borg', 'key', 'import', '--log-json', 'repo', 'source'),
input_file=None,
working_directory='/working/dir',
)
+75 -47
View File
@@ -28,7 +28,7 @@ def test_make_info_command_constructs_borg_info_command():
remote_path=None,
)
assert command == ('borg', 'info', '--repo', 'repo')
assert command == ('borg', 'info', '--log-json', '--repo', 'repo')
def test_make_info_command_with_log_info_passes_through_to_command():
@@ -52,7 +52,7 @@ def test_make_info_command_with_log_info_passes_through_to_command():
remote_path=None,
)
assert command == ('borg', 'info', '--info', '--repo', 'repo')
assert command == ('borg', 'info', '--info', '--log-json', '--repo', 'repo')
def test_make_info_command_with_log_info_and_json_omits_borg_logging_flags():
@@ -76,7 +76,7 @@ def test_make_info_command_with_log_info_and_json_omits_borg_logging_flags():
remote_path=None,
)
assert command == ('borg', 'info', '--json', '--repo', 'repo')
assert command == ('borg', 'info', '--log-json', '--json', '--repo', 'repo')
def test_make_info_command_with_log_debug_passes_through_to_command():
@@ -100,7 +100,7 @@ def test_make_info_command_with_log_debug_passes_through_to_command():
remote_path=None,
)
assert command == ('borg', 'info', '--debug', '--show-rc', '--repo', 'repo')
assert command == ('borg', 'info', '--debug', '--show-rc', '--log-json', '--repo', 'repo')
def test_make_info_command_with_log_debug_and_json_omits_borg_logging_flags():
@@ -123,7 +123,7 @@ def test_make_info_command_with_log_debug_and_json_omits_borg_logging_flags():
remote_path=None,
)
assert command == ('borg', 'info', '--json', '--repo', 'repo')
assert command == ('borg', 'info', '--log-json', '--json', '--repo', 'repo')
def test_make_info_command_with_json_passes_through_to_command():
@@ -146,7 +146,7 @@ def test_make_info_command_with_json_passes_through_to_command():
remote_path=None,
)
assert command == ('borg', 'info', '--json', '--repo', 'repo')
assert command == ('borg', 'info', '--log-json', '--json', '--repo', 'repo')
def test_make_info_command_with_archive_uses_match_archives_flags():
@@ -169,7 +169,15 @@ def test_make_info_command_with_archive_uses_match_archives_flags():
remote_path=None,
)
assert command == ('borg', 'info', '--match-archives', 'archive', '--repo', 'repo')
assert command == (
'borg',
'info',
'--log-json',
'--match-archives',
'archive',
'--repo',
'repo',
)
def test_make_info_command_with_local_path_passes_through_to_command():
@@ -192,7 +200,7 @@ def test_make_info_command_with_local_path_passes_through_to_command():
remote_path=None,
)
assert command == ('borg1', 'info', '--repo', 'repo')
assert command == ('borg1', 'info', '--log-json', '--repo', 'repo')
def test_make_info_command_with_remote_path_passes_through_to_command():
@@ -219,7 +227,7 @@ def test_make_info_command_with_remote_path_passes_through_to_command():
remote_path='borg1',
)
assert command == ('borg', 'info', '--remote-path', 'borg1', '--repo', 'repo')
assert command == ('borg', 'info', '--remote-path', 'borg1', '--log-json', '--repo', 'repo')
def test_make_info_command_with_umask_passes_through_to_command():
@@ -244,33 +252,7 @@ def test_make_info_command_with_umask_passes_through_to_command():
remote_path=None,
)
assert command == ('borg', 'info', '--umask', '077', '--repo', 'repo')
def test_make_info_command_with_log_json_passes_through_to_command():
flexmock(module.flags).should_receive('make_flags').and_return(())
flexmock(module.flags).should_receive('make_flags').with_args('log-json', True).and_return(
('--log-json',),
)
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'))
command = module.make_info_command(
repository_path='repo',
config={'log_json': True},
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', '--log-json', '--repo', 'repo')
assert command == ('borg', 'info', '--umask', '077', '--log-json', '--repo', 'repo')
def test_make_info_command_with_lock_wait_passes_through_to_command():
@@ -297,7 +279,7 @@ def test_make_info_command_with_lock_wait_passes_through_to_command():
remote_path=None,
)
assert command == ('borg', 'info', '--lock-wait', '5', '--repo', 'repo')
assert command == ('borg', 'info', '--log-json', '--lock-wait', '5', '--repo', 'repo')
def test_make_info_command_with_extra_borg_options_passes_through_to_command():
@@ -321,7 +303,15 @@ def test_make_info_command_with_extra_borg_options_passes_through_to_command():
remote_path=None,
)
assert command == ('borg', 'info', '--extra', 'value with space', '--repo', 'repo')
assert command == (
'borg',
'info',
'--log-json',
'--extra',
'value with space',
'--repo',
'repo',
)
def test_make_info_command_transforms_prefix_into_match_archives_flags():
@@ -348,7 +338,15 @@ def test_make_info_command_transforms_prefix_into_match_archives_flags():
remote_path=None,
)
assert command == ('borg', 'info', '--match-archives', 'sh:foo*', '--repo', 'repo')
assert command == (
'borg',
'info',
'--log-json',
'--match-archives',
'sh:foo*',
'--repo',
'repo',
)
def test_make_info_command_prefers_prefix_over_archive_name_format():
@@ -375,7 +373,15 @@ def test_make_info_command_prefers_prefix_over_archive_name_format():
remote_path=None,
)
assert command == ('borg', 'info', '--match-archives', 'sh:foo*', '--repo', 'repo')
assert command == (
'borg',
'info',
'--log-json',
'--match-archives',
'sh:foo*',
'--repo',
'repo',
)
def test_make_info_command_transforms_archive_name_format_into_match_archives_flags():
@@ -398,7 +404,15 @@ def test_make_info_command_transforms_archive_name_format_into_match_archives_fl
remote_path=None,
)
assert command == ('borg', 'info', '--match-archives', 'sh:bar-*', '--repo', 'repo')
assert command == (
'borg',
'info',
'--log-json',
'--match-archives',
'sh:bar-*',
'--repo',
'repo',
)
def test_make_info_command_with_match_archives_option_passes_through_to_command():
@@ -425,7 +439,15 @@ def test_make_info_command_with_match_archives_option_passes_through_to_command(
remote_path=None,
)
assert command == ('borg', 'info', '--match-archives', 'sh:foo-*', '--repo', 'repo')
assert command == (
'borg',
'info',
'--log-json',
'--match-archives',
'sh:foo-*',
'--repo',
'repo',
)
def test_make_info_command_with_match_archives_flag_passes_through_to_command():
@@ -449,7 +471,15 @@ def test_make_info_command_with_match_archives_flag_passes_through_to_command():
remote_path=None,
)
assert command == ('borg', 'info', '--match-archives', 'sh:foo-*', '--repo', 'repo')
assert command == (
'borg',
'info',
'--log-json',
'--match-archives',
'sh:foo-*',
'--repo',
'repo',
)
@pytest.mark.parametrize('argument_name', ('sort_by', 'first', 'last'))
@@ -483,7 +513,7 @@ def test_make_info_command_passes_arguments_through_to_command(argument_name):
remote_path=None,
)
assert command == ('borg', 'info', flag_name, 'value', '--repo', 'repo')
assert command == ('borg', 'info', '--log-json', flag_name, 'value', '--repo', 'repo')
def test_make_info_command_with_date_based_matching_passes_through_to_command():
@@ -521,6 +551,7 @@ def test_make_info_command_with_date_based_matching_passes_through_to_command():
assert command == (
'borg',
'info',
'--log-json',
'--newer',
'1d',
'--newest',
@@ -535,7 +566,6 @@ def test_make_info_command_with_date_based_matching_passes_through_to_command():
def test_display_archives_info_calls_two_commands():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module).should_receive('make_info_command')
flexmock(module.environment).should_receive('make_environment')
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
@@ -553,7 +583,6 @@ def test_display_archives_info_calls_two_commands():
def test_display_archives_info_with_json_calls_json_command_only():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module).should_receive('make_info_command')
flexmock(module.environment).should_receive('make_environment')
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
@@ -575,7 +604,6 @@ def test_display_archives_info_with_json_calls_json_command_only():
def test_display_archives_info_calls_borg_with_working_directory():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module).should_receive('make_info_command')
flexmock(module.environment).should_receive('make_environment')
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
+44 -55
View File
@@ -23,7 +23,7 @@ def test_make_list_command_includes_log_info():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--info', 'repo')
assert command == ('borg', 'list', '--info', '--log-json', 'repo')
def test_make_list_command_includes_json_but_not_info():
@@ -40,7 +40,7 @@ def test_make_list_command_includes_json_but_not_info():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--json', 'repo')
assert command == ('borg', 'list', '--log-json', '--json', 'repo')
def test_make_list_command_includes_log_debug():
@@ -57,7 +57,7 @@ def test_make_list_command_includes_log_debug():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--debug', '--show-rc', 'repo')
assert command == ('borg', 'list', '--debug', '--show-rc', '--log-json', 'repo')
def test_make_list_command_includes_json_but_not_debug():
@@ -74,7 +74,7 @@ def test_make_list_command_includes_json_but_not_debug():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--json', 'repo')
assert command == ('borg', 'list', '--log-json', '--json', 'repo')
def test_make_list_command_includes_json():
@@ -90,25 +90,7 @@ def test_make_list_command_includes_json():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--json', 'repo')
def test_make_list_command_includes_log_json():
flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(()).and_return(
('--log-json',),
).and_return(())
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={'log_json': True},
local_borg_version='1.2.3',
list_arguments=flexmock(archive=None, paths=None, format=None, json=False),
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--log-json', 'repo')
assert command == ('borg', 'list', '--log-json', '--json', 'repo')
def test_make_list_command_includes_lock_wait():
@@ -126,7 +108,7 @@ def test_make_list_command_includes_lock_wait():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--lock-wait', '5', 'repo')
assert command == ('borg', 'list', '--log-json', '--lock-wait', '5', 'repo')
def test_make_list_command_includes_format():
@@ -144,7 +126,7 @@ def test_make_list_command_includes_format():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--format', 'stuff', 'repo')
assert command == ('borg', 'list', '--log-json', '--format', 'stuff', 'repo')
def test_make_list_command_includes_extra_borg_options():
@@ -160,7 +142,7 @@ def test_make_list_command_includes_extra_borg_options():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--extra', 'value with space', 'repo')
assert command == ('borg', 'list', '--log-json', '--extra', 'value with space', 'repo')
def test_make_list_command_includes_archive():
@@ -178,7 +160,7 @@ def test_make_list_command_includes_archive():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', 'repo::archive')
assert command == ('borg', 'list', '--log-json', 'repo::archive')
def test_make_list_command_includes_archive_and_path():
@@ -196,7 +178,7 @@ def test_make_list_command_includes_archive_and_path():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', 'repo::archive', 'var/lib')
assert command == ('borg', 'list', '--log-json', 'repo::archive', 'var/lib')
def test_make_list_command_includes_local_path():
@@ -213,7 +195,7 @@ def test_make_list_command_includes_local_path():
local_path='borg2',
)
assert command == ('borg2', 'list', 'repo')
assert command == ('borg2', 'list', '--log-json', 'repo')
def test_make_list_command_includes_remote_path():
@@ -237,7 +219,7 @@ def test_make_list_command_includes_remote_path():
remote_path='borg2',
)
assert command == ('borg', 'list', '--remote-path', 'borg2', 'repo')
assert command == ('borg', 'list', '--remote-path', 'borg2', '--log-json', 'repo')
def test_make_list_command_includes_umask():
@@ -255,7 +237,7 @@ def test_make_list_command_includes_umask():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--umask', '077', 'repo')
assert command == ('borg', 'list', '--umask', '077', '--log-json', 'repo')
def test_make_list_command_includes_short():
@@ -271,7 +253,7 @@ def test_make_list_command_includes_short():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--short', 'repo')
assert command == ('borg', 'list', '--log-json', '--short', 'repo')
@pytest.mark.parametrize(
@@ -310,7 +292,14 @@ def test_make_list_command_includes_additional_flags(argument_name):
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--' + argument_name.replace('_', '-'), 'value', 'repo')
assert command == (
'borg',
'list',
'--log-json',
'--' + argument_name.replace('_', '-'),
'value',
'repo',
)
def test_make_find_paths_considers_none_as_empty_paths():
@@ -382,12 +371,12 @@ def test_list_archive_calls_borg_with_flags():
global_arguments=global_arguments,
local_path='borg',
remote_path=None,
).and_return(('borg', 'list', 'repo::archive'))
).and_return(('borg', 'list', '--log-json', 'repo::archive'))
flexmock(module).should_receive('make_find_paths').and_return(())
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', 'list', 'repo::archive'),
('borg', 'list', '--log-json', 'repo::archive'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -449,12 +438,12 @@ def test_list_archive_calls_borg_with_local_path():
global_arguments=global_arguments,
local_path='borg2',
remote_path=None,
).and_return(('borg2', 'list', 'repo::archive'))
).and_return(('borg2', 'list', '--log-json', 'repo::archive'))
flexmock(module).should_receive('make_find_paths').and_return(())
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(
('borg2', 'list', 'repo::archive'),
('borg2', 'list', '--log-json', 'repo::archive'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -499,12 +488,12 @@ def test_list_archive_calls_borg_using_exit_codes():
global_arguments=global_arguments,
local_path='borg',
remote_path=None,
).and_return(('borg', 'list', 'repo::archive'))
).and_return(('borg', 'list', '--log-json', 'repo::archive'))
flexmock(module).should_receive('make_find_paths').and_return(())
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', 'list', 'repo::archive'),
('borg', 'list', '--log-json', 'repo::archive'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -539,23 +528,23 @@ def test_list_archive_calls_borg_multiple_times_with_find_paths():
flexmock(module.feature).should_receive('available').and_return(False)
flexmock(module.repo_list).should_receive('make_repo_list_command').and_return(
('borg', 'list', 'repo'),
('borg', 'list', '--log-json', 'repo'),
)
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', 'repo'),
('borg', 'list', '--log-json', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
).and_return('archive1\narchive2').once()
flexmock(module).should_receive('make_list_command').and_return(
('borg', 'list', 'repo::archive1'),
).and_return(('borg', 'list', 'repo::archive2'))
('borg', 'list', '--log-json', 'repo::archive1'),
).and_return(('borg', 'list', '--log-json', 'repo::archive2'))
flexmock(module).should_receive('make_find_paths').and_return(glob_paths)
flexmock(module.environment).should_receive('make_environment')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'list', 'repo::archive1', *glob_paths),
('borg', 'list', '--log-json', 'repo::archive1', *glob_paths),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -563,7 +552,7 @@ def test_list_archive_calls_borg_multiple_times_with_find_paths():
borg_exit_codes=None,
).once()
flexmock(module).should_receive('execute_command').with_args(
('borg', 'list', 'repo::archive2', *glob_paths),
('borg', 'list', '--log-json', 'repo::archive2', *glob_paths),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -606,12 +595,12 @@ def test_list_archive_calls_borg_with_archive():
global_arguments=global_arguments,
local_path='borg',
remote_path=None,
).and_return(('borg', 'list', 'repo::archive'))
).and_return(('borg', 'list', '--log-json', 'repo::archive'))
flexmock(module).should_receive('make_find_paths').and_return(())
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', 'list', 'repo::archive'),
('borg', 'list', '--log-json', 'repo::archive'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -734,12 +723,12 @@ def test_list_archive_with_archive_ignores_archive_filter_flag(
global_arguments=global_arguments,
local_path='borg',
remote_path=None,
).and_return(('borg', 'list', 'repo::archive'))
).and_return(('borg', 'list', '--log-json', 'repo::archive'))
flexmock(module).should_receive('make_find_paths').and_return(())
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', 'list', 'repo::archive'),
('borg', 'list', '--log-json', 'repo::archive'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -832,7 +821,7 @@ def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes
global_arguments=global_arguments,
local_path='borg',
remote_path=None,
).and_return(('borg', 'list', '--repo', 'repo', 'archive1'))
).and_return(('borg', 'list', '--log-json', '--repo', 'repo', 'archive1'))
flexmock(module).should_receive('make_list_command').with_args(
repository_path='repo',
@@ -851,12 +840,12 @@ def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes
global_arguments=global_arguments,
local_path='borg',
remote_path=None,
).and_return(('borg', 'list', '--repo', 'repo', 'archive2'))
).and_return(('borg', 'list', '--log-json', '--repo', 'repo', 'archive2'))
flexmock(module).should_receive('make_find_paths').and_return(glob_paths)
flexmock(module.environment).should_receive('make_environment')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'list', '--repo', 'repo', 'archive1', *glob_paths),
('borg', 'list', '--log-json', '--repo', 'repo', 'archive1', *glob_paths),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -864,7 +853,7 @@ def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes
borg_exit_codes=None,
).once()
flexmock(module).should_receive('execute_command').with_args(
('borg', 'list', '--repo', 'repo', 'archive2', *glob_paths),
('borg', 'list', '--log-json', '--repo', 'repo', 'archive2', *glob_paths),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -916,14 +905,14 @@ def test_list_archive_calls_borg_with_working_directory():
global_arguments=global_arguments,
local_path='borg',
remote_path=None,
).and_return(('borg', 'list', 'repo::archive'))
).and_return(('borg', 'list', '--log-json', 'repo::archive'))
flexmock(module).should_receive('make_find_paths').and_return(())
flexmock(module.environment).should_receive('make_environment')
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
'/working/dir',
)
flexmock(module).should_receive('execute_command').with_args(
('borg', 'list', 'repo::archive'),
('borg', 'list', '--log-json', 'repo::archive'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory='/working/dir',
+28 -33
View File
@@ -24,7 +24,7 @@ def insert_execute_command_mock(command, working_directory=None, borg_exit_codes
def test_mount_archive_calls_borg_with_required_flags():
flexmock(module.feature).should_receive('available').and_return(False)
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'mount', 'repo', '/mnt'))
insert_execute_command_mock(('borg', 'mount', '--log-json', 'repo', '/mnt'))
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive(
@@ -46,7 +46,7 @@ def test_mount_archive_with_borg_features_calls_borg_with_repository_and_match_a
),
)
insert_execute_command_mock(
('borg', 'mount', '--repo', 'repo', '--match-archives', 'archive', '/mnt'),
('borg', 'mount', '--log-json', '--repo', 'repo', '--match-archives', 'archive', '/mnt'),
)
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
@@ -65,7 +65,7 @@ def test_mount_archive_without_archive_calls_borg_with_repository_flags_only():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt'))
insert_execute_command_mock(('borg', 'mount', '--log-json', 'repo::archive', '/mnt'))
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive(
@@ -83,7 +83,9 @@ def test_mount_archive_calls_borg_with_path_flags():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt', 'path1', 'path2'))
insert_execute_command_mock(
('borg', 'mount', '--log-json', 'repo::archive', '/mnt', 'path1', 'path2')
)
mount_arguments = flexmock(
mount_point='/mnt',
@@ -106,7 +108,7 @@ def test_mount_archive_calls_borg_with_local_path():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
insert_execute_command_mock(('borg1', 'mount', 'repo::archive', '/mnt'))
insert_execute_command_mock(('borg1', 'mount', '--log-json', 'repo::archive', '/mnt'))
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive(
@@ -127,7 +129,7 @@ def test_mount_archive_calls_borg_using_exit_codes():
)
borg_exit_codes = flexmock()
insert_execute_command_mock(
('borg', 'mount', 'repo::archive', '/mnt'),
('borg', 'mount', '--log-json', 'repo::archive', '/mnt'),
borg_exit_codes=borg_exit_codes,
)
@@ -148,7 +150,7 @@ def test_mount_archive_calls_borg_with_remote_path_flags():
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'mount', '--remote-path', 'borg1', 'repo::archive', '/mnt'),
('borg', 'mount', '--remote-path', 'borg1', '--log-json', 'repo::archive', '/mnt'),
)
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
@@ -168,7 +170,9 @@ def test_mount_archive_calls_borg_with_umask_flags():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
insert_execute_command_mock(('borg', 'mount', '--umask', '0770', 'repo::archive', '/mnt'))
insert_execute_command_mock(
('borg', 'mount', '--umask', '0770', '--log-json', 'repo::archive', '/mnt')
)
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive(
@@ -181,30 +185,14 @@ def test_mount_archive_calls_borg_with_umask_flags():
)
def test_mount_archive_calls_borg_with_log_json_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', '--log-json', 'repo::archive', '/mnt'))
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={'log_json': True},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
def test_mount_archive_calls_borg_with_lock_wait_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', '--lock-wait', '5', 'repo::archive', '/mnt'))
insert_execute_command_mock(
('borg', 'mount', '--log-json', '--lock-wait', '5', 'repo::archive', '/mnt')
)
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive(
@@ -223,7 +211,7 @@ def test_mount_archive_calls_borg_with_extra_borg_options():
('repo::archive',),
)
insert_execute_command_mock(
('borg', 'mount', '--extra', 'value with space', 'repo::archive', '/mnt')
('borg', 'mount', '--log-json', '--extra', 'value with space', 'repo::archive', '/mnt')
)
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
@@ -242,7 +230,7 @@ def test_mount_archive_with_log_info_calls_borg_with_info_parameter():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
insert_execute_command_mock(('borg', 'mount', '--info', 'repo::archive', '/mnt'))
insert_execute_command_mock(('borg', 'mount', '--log-json', '--info', 'repo::archive', '/mnt'))
insert_logging_mock(logging.INFO)
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
@@ -261,7 +249,9 @@ def test_mount_archive_with_log_debug_calls_borg_with_debug_flags():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
insert_execute_command_mock(('borg', 'mount', '--debug', '--show-rc', 'repo::archive', '/mnt'))
insert_execute_command_mock(
('borg', 'mount', '--log-json', '--debug', '--show-rc', 'repo::archive', '/mnt')
)
insert_logging_mock(logging.DEBUG)
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
@@ -283,7 +273,7 @@ def test_mount_archive_calls_borg_with_foreground_parameter():
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', 'mount', '--foreground', 'repo::archive', '/mnt'),
('borg', 'mount', '--log-json', '--foreground', 'repo::archive', '/mnt'),
output_file=module.DO_NOT_CAPTURE,
environment=None,
working_directory=None,
@@ -307,7 +297,9 @@ def test_mount_archive_calls_borg_with_options_flags():
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
('repo::archive',),
)
insert_execute_command_mock(('borg', 'mount', '-o', 'super_mount', 'repo::archive', '/mnt'))
insert_execute_command_mock(
('borg', 'mount', '--log-json', '-o', 'super_mount', 'repo::archive', '/mnt')
)
mount_arguments = flexmock(
mount_point='/mnt',
@@ -349,6 +341,7 @@ def test_mount_archive_with_date_based_matching_calls_borg_with_date_based_flags
(
'borg',
'mount',
'--log-json',
'--newer',
'1d',
'--newest',
@@ -392,7 +385,9 @@ def test_mount_archive_with_date_based_matching_calls_borg_with_date_based_flags
def test_mount_archive_calls_borg_with_working_directory():
flexmock(module.feature).should_receive('available').and_return(False)
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
insert_execute_command_mock(('borg', 'mount', 'repo', '/mnt'), working_directory='/working/dir')
insert_execute_command_mock(
('borg', 'mount', '--log-json', 'repo', '/mnt'), working_directory='/working/dir'
)
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
module.mount_archive(
+12 -23
View File
@@ -221,7 +221,17 @@ def test_make_prune_flags_ignores_keep_exclude_tags_in_config():
assert result == ('--keep-daily', '1')
PRUNE_COMMAND = ('borg', 'prune', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3')
PRUNE_COMMAND = (
'borg',
'prune',
'--keep-daily',
'1',
'--keep-weekly',
'2',
'--keep-monthly',
'3',
'--log-json',
)
def test_prune_archives_calls_borg_with_flags():
@@ -454,28 +464,6 @@ def test_prune_archives_with_umask_calls_borg_with_umask_flags():
)
def test_prune_archives_with_log_json_calls_borg_with_log_json_flag():
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, '--log-json', 'repo'), logging.INFO)
prune_arguments = flexmock(statistics=False, list_details=False)
module.prune_archives(
dry_run=False,
repository_path='repo',
config={'log_json': True},
local_borg_version='1.2.3',
global_arguments=flexmock(),
prune_arguments=prune_arguments,
)
def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
@@ -561,6 +549,7 @@ def test_prune_archives_with_date_based_matching_calls_borg_with_date_based_flag
'2',
'--keep-monthly',
'3',
'--log-json',
'--newer',
'1d',
'--newest',
+46 -56
View File
@@ -72,7 +72,7 @@ def test_recreate_calls_borg_with_required_flags():
'repo',
),
)
insert_execute_command_mock(('borg', 'recreate', '--repo', 'repo'))
insert_execute_command_mock(('borg', 'recreate', '--log-json', '--repo', 'repo'))
module.recreate_archive(
repository='repo',
@@ -107,7 +107,9 @@ def test_recreate_with_remote_path():
'repo',
),
)
insert_execute_command_mock(('borg', 'recreate', '--remote-path', 'borg1', '--repo', 'repo'))
insert_execute_command_mock(
('borg', 'recreate', '--remote-path', 'borg1', '--log-json', '--repo', 'repo')
)
module.recreate_archive(
repository='repo',
@@ -142,7 +144,9 @@ def test_recreate_with_lock_wait():
'repo',
),
)
insert_execute_command_mock(('borg', 'recreate', '--lock-wait', '5', '--repo', 'repo'))
insert_execute_command_mock(
('borg', 'recreate', '--log-json', '--lock-wait', '5', '--repo', 'repo')
)
module.recreate_archive(
repository='repo',
@@ -177,7 +181,7 @@ def test_recreate_with_extra_borg_options():
),
)
insert_execute_command_mock(
('borg', 'recreate', '--extra', 'value with space', '--repo', 'repo')
('borg', 'recreate', '--log-json', '--extra', 'value with space', '--repo', 'repo')
)
module.recreate_archive(
@@ -212,7 +216,7 @@ def test_recreate_with_log_info():
'repo',
),
)
insert_execute_command_mock(('borg', 'recreate', '--info', '--repo', 'repo'))
insert_execute_command_mock(('borg', 'recreate', '--log-json', '--info', '--repo', 'repo'))
insert_logging_mock(logging.INFO)
@@ -248,7 +252,9 @@ def test_recreate_with_log_debug():
'repo',
),
)
insert_execute_command_mock(('borg', 'recreate', '--debug', '--show-rc', '--repo', 'repo'))
insert_execute_command_mock(
('borg', 'recreate', '--log-json', '--debug', '--show-rc', '--repo', 'repo')
)
insert_logging_mock(logging.DEBUG)
module.recreate_archive(
@@ -269,40 +275,6 @@ def test_recreate_with_log_debug():
)
def test_recreate_with_log_json():
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', '--log-json', '--repo', 'repo'))
module.recreate_archive(
repository='repo',
archive='archive',
config={'log_json': True},
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_list_config_calls_borg_with_list_flag():
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)
@@ -320,7 +292,7 @@ def test_recreate_with_list_config_calls_borg_with_list_flag():
'AME+-',
)
insert_execute_command_mock(
('borg', 'recreate', '--list', '--filter', 'AME+-', '--repo', 'repo'),
('borg', 'recreate', '--log-json', '--list', '--filter', 'AME+-', '--repo', 'repo'),
)
module.recreate_archive(
@@ -357,7 +329,7 @@ def test_recreate_with_patterns_from_flag():
mock_patterns_file = flexmock(name='patterns_file')
flexmock(module).should_receive('write_patterns_file').and_return(mock_patterns_file)
insert_execute_command_mock(
('borg', 'recreate', '--patterns-from', 'patterns_file', '--repo', 'repo'),
('borg', 'recreate', '--log-json', '--patterns-from', 'patterns_file', '--repo', 'repo'),
)
module.recreate_archive(
@@ -394,7 +366,9 @@ def test_recreate_with_exclude_flags():
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(
('--exclude', 'pattern'),
)
insert_execute_command_mock(('borg', 'recreate', '--exclude', 'pattern', '--repo', 'repo'))
insert_execute_command_mock(
('borg', 'recreate', '--log-json', '--exclude', 'pattern', '--repo', 'repo')
)
module.recreate_archive(
repository='repo',
@@ -428,7 +402,9 @@ def test_recreate_with_target_flag():
'repo',
),
)
insert_execute_command_mock(('borg', 'recreate', '--target', 'new-archive', '--repo', 'repo'))
insert_execute_command_mock(
('borg', 'recreate', '--log-json', '--target', 'new-archive', '--repo', 'repo')
)
module.recreate_archive(
repository='repo',
@@ -463,7 +439,15 @@ def test_recreate_with_comment_flag():
),
)
insert_execute_command_mock(
('borg', 'recreate', '--comment', shlex.quote('This is a test comment'), '--repo', 'repo'),
(
'borg',
'recreate',
'--log-json',
'--comment',
shlex.quote('This is a test comment'),
'--repo',
'repo',
),
)
module.recreate_archive(
@@ -499,7 +483,7 @@ def test_recreate_with_timestamp_flag():
),
)
insert_execute_command_mock(
('borg', 'recreate', '--timestamp', '2023-10-01T12:00:00', '--repo', 'repo'),
('borg', 'recreate', '--log-json', '--timestamp', '2023-10-01T12:00:00', '--repo', 'repo'),
)
module.recreate_archive(
@@ -534,7 +518,9 @@ def test_recreate_with_compression_flag():
'repo',
),
)
insert_execute_command_mock(('borg', 'recreate', '--compression', 'lz4', '--repo', 'repo'))
insert_execute_command_mock(
('borg', 'recreate', '--log-json', '--compression', 'lz4', '--repo', 'repo')
)
module.recreate_archive(
repository='repo',
@@ -569,7 +555,7 @@ def test_recreate_with_chunker_params_flag():
),
)
insert_execute_command_mock(
('borg', 'recreate', '--chunker-params', '19,23,21,4095', '--repo', 'repo'),
('borg', 'recreate', '--log-json', '--chunker-params', '19,23,21,4095', '--repo', 'repo'),
)
module.recreate_archive(
@@ -604,7 +590,9 @@ def test_recreate_with_recompress_flag():
'repo',
),
)
insert_execute_command_mock(('borg', 'recreate', '--recompress', 'always', '--repo', 'repo'))
insert_execute_command_mock(
('borg', 'recreate', '--log-json', '--recompress', 'always', '--repo', 'repo')
)
module.recreate_archive(
repository='repo',
@@ -638,7 +626,7 @@ def test_recreate_with_match_archives_star():
'repo',
),
)
insert_execute_command_mock(('borg', 'recreate', '--repo', 'repo'))
insert_execute_command_mock(('borg', 'recreate', '--log-json', '--repo', 'repo'))
module.recreate_archive(
repository='repo',
@@ -672,7 +660,7 @@ def test_recreate_with_match_archives_regex():
'repo',
),
)
insert_execute_command_mock(('borg', 'recreate', '--repo', 'repo'))
insert_execute_command_mock(('borg', 'recreate', '--log-json', '--repo', 'repo'))
module.recreate_archive(
repository='repo',
@@ -706,7 +694,7 @@ def test_recreate_with_match_archives_shell():
'repo',
),
)
insert_execute_command_mock(('borg', 'recreate', '--repo', 'repo'))
insert_execute_command_mock(('borg', 'recreate', '--log-json', '--repo', 'repo'))
module.recreate_archive(
repository='repo',
@@ -740,7 +728,9 @@ def test_recreate_with_match_archives_and_feature_available_calls_borg_with_matc
('--repo', 'repo'),
)
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_archive_flags').never()
insert_execute_command_mock(('borg', 'recreate', '--repo', 'repo', '--match-archives', 'foo-*'))
insert_execute_command_mock(
('borg', 'recreate', '--log-json', '--repo', 'repo', '--match-archives', 'foo-*')
)
module.recreate_archive(
repository='repo',
@@ -775,7 +765,7 @@ def test_recreate_with_archives_flag_and_feature_available_calls_borg_with_match
)
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_archive_flags').never()
insert_execute_command_mock(
('borg', 'recreate', '--repo', 'repo', '--match-archives', 'archive'),
('borg', 'recreate', '--log-json', '--repo', 'repo', '--match-archives', 'archive'),
)
module.recreate_archive(
@@ -806,7 +796,7 @@ def test_recreate_with_match_archives_and_feature_not_available_calls_borg_witho
('repo',),
)
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_archive_flags').never()
insert_execute_command_mock(('borg', 'recreate', 'repo'))
insert_execute_command_mock(('borg', 'recreate', '--log-json', 'repo'))
module.recreate_archive(
repository='repo',
@@ -836,7 +826,7 @@ def test_recreate_with_archives_flags_and_feature_not_available_calls_borg_with_
'make_repository_archive_flags',
).and_return(('repo::archive',))
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').never()
insert_execute_command_mock(('borg', 'recreate', 'repo::archive'))
insert_execute_command_mock(('borg', 'recreate', '--log-json', 'repo::archive'))
module.recreate_archive(
repository='repo',
+1 -22
View File
@@ -9,7 +9,7 @@ from borgmatic.borg import repo_create as module
from ..test_verbosity import insert_logging_mock
REPO_INFO_SOME_UNKNOWN_EXIT_CODE = -999
REPO_CREATE_COMMAND = ('borg', 'repo-create', '--encryption', 'repokey')
REPO_CREATE_COMMAND = ('borg', 'repo-create', '--log-json', '--encryption', 'repokey')
def insert_repo_info_command_found_mock():
@@ -352,27 +352,6 @@ def test_create_repository_with_log_debug_calls_borg_with_debug_flag():
)
def test_create_repository_with_log_json_calls_borg_with_log_json_flag():
insert_repo_info_command_not_found_mock()
insert_repo_create_command_mock((*REPO_CREATE_COMMAND, '--log-json', '--repo', 'repo'))
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={'log_json': True},
local_borg_version='2.3.4',
global_arguments=flexmock(),
encryption_mode='repokey',
)
def test_create_repository_with_lock_wait_calls_borg_with_lock_wait_flag():
insert_repo_info_command_not_found_mock()
insert_repo_create_command_mock((*REPO_CREATE_COMMAND, '--lock-wait', '5', '--repo', 'repo'))
+17 -42
View File
@@ -25,7 +25,7 @@ def test_make_repo_delete_command_with_feature_available_runs_borg_repo_delete()
remote_path=None,
)
assert command == ('borg', 'repo-delete', 'repo')
assert command == ('borg', 'repo-delete', '--log-json', 'repo')
def test_make_repo_delete_command_without_feature_available_runs_borg_delete():
@@ -46,7 +46,7 @@ def test_make_repo_delete_command_without_feature_available_runs_borg_delete():
remote_path=None,
)
assert command == ('borg', 'delete', 'repo')
assert command == ('borg', 'delete', '--log-json', 'repo')
def test_make_repo_delete_command_includes_log_info():
@@ -68,7 +68,7 @@ def test_make_repo_delete_command_includes_log_info():
remote_path=None,
)
assert command == ('borg', 'repo-delete', '--info', 'repo')
assert command == ('borg', 'repo-delete', '--info', '--log-json', 'repo')
def test_make_repo_delete_command_includes_log_debug():
@@ -90,7 +90,7 @@ def test_make_repo_delete_command_includes_log_debug():
remote_path=None,
)
assert command == ('borg', 'repo-delete', '--debug', '--show-rc', 'repo')
assert command == ('borg', 'repo-delete', '--debug', '--show-rc', '--log-json', 'repo')
def test_make_repo_delete_command_includes_dry_run():
@@ -115,7 +115,7 @@ def test_make_repo_delete_command_includes_dry_run():
remote_path=None,
)
assert command == ('borg', 'repo-delete', '--dry-run', 'repo')
assert command == ('borg', 'repo-delete', '--dry-run', '--log-json', 'repo')
def test_make_repo_delete_command_includes_remote_path():
@@ -140,7 +140,7 @@ def test_make_repo_delete_command_includes_remote_path():
remote_path='borg1',
)
assert command == ('borg', 'repo-delete', '--remote-path', 'borg1', 'repo')
assert command == ('borg', 'repo-delete', '--remote-path', 'borg1', '--log-json', 'repo')
def test_make_repo_delete_command_includes_umask():
@@ -163,32 +163,7 @@ def test_make_repo_delete_command_includes_umask():
remote_path=None,
)
assert command == ('borg', 'repo-delete', '--umask', '077', 'repo')
def test_make_repo_delete_command_includes_log_json():
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(
'log-json',
True,
).and_return(('--log-json',))
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={'log_json': True},
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,
)
assert command == ('borg', 'repo-delete', '--log-json', 'repo')
assert command == ('borg', 'repo-delete', '--umask', '077', '--log-json', 'repo')
def test_make_repo_delete_command_includes_lock_wait():
@@ -213,7 +188,7 @@ def test_make_repo_delete_command_includes_lock_wait():
remote_path=None,
)
assert command == ('borg', 'repo-delete', '--lock-wait', '5', 'repo')
assert command == ('borg', 'repo-delete', '--log-json', '--lock-wait', '5', 'repo')
def test_make_repo_delete_command_without_feature_available_includes_delete_extra_borg_options():
@@ -234,7 +209,7 @@ def test_make_repo_delete_command_without_feature_available_includes_delete_extr
remote_path=None,
)
assert command == ('borg', 'delete', '--extra', 'value with space', 'repo')
assert command == ('borg', 'delete', '--log-json', '--extra', 'value with space', 'repo')
def test_make_repo_delete_command_with_feature_available_includes_delete_extra_borg_options():
@@ -255,7 +230,7 @@ def test_make_repo_delete_command_with_feature_available_includes_delete_extra_b
remote_path=None,
)
assert command == ('borg', 'repo-delete', '--extra', 'value with space', 'repo')
assert command == ('borg', 'repo-delete', '--log-json', '--extra', 'value with space', 'repo')
def test_make_repo_delete_command_includes_list():
@@ -280,7 +255,7 @@ def test_make_repo_delete_command_includes_list():
remote_path=None,
)
assert command == ('borg', 'repo-delete', '--list', 'repo')
assert command == ('borg', 'repo-delete', '--log-json', '--list', 'repo')
def test_make_repo_delete_command_includes_force():
@@ -301,7 +276,7 @@ def test_make_repo_delete_command_includes_force():
remote_path=None,
)
assert command == ('borg', 'repo-delete', '--force', 'repo')
assert command == ('borg', 'repo-delete', '--log-json', '--force', 'repo')
def test_make_repo_delete_command_includes_force_twice():
@@ -322,11 +297,11 @@ def test_make_repo_delete_command_includes_force_twice():
remote_path=None,
)
assert command == ('borg', 'repo-delete', '--force', '--force', 'repo')
assert command == ('borg', 'repo-delete', '--log-json', '--force', '--force', 'repo')
def test_delete_repository_with_defaults_does_not_capture_output():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
module.borgmatic.logger.add_custom_log_levels()
command = flexmock()
flexmock(module).should_receive('make_repo_delete_command').and_return(command)
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
@@ -355,7 +330,7 @@ def test_delete_repository_with_defaults_does_not_capture_output():
def test_delete_repository_with_force_captures_output():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
module.borgmatic.logger.add_custom_log_levels()
command = flexmock()
flexmock(module).should_receive('make_repo_delete_command').and_return(command)
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
@@ -384,7 +359,7 @@ def test_delete_repository_with_force_captures_output():
def test_delete_repository_with_cache_only_captures_output():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
module.borgmatic.logger.add_custom_log_levels()
command = flexmock()
flexmock(module).should_receive('make_repo_delete_command').and_return(command)
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
@@ -413,7 +388,7 @@ def test_delete_repository_with_cache_only_captures_output():
def test_delete_repository_calls_borg_with_working_directory():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
module.borgmatic.logger.add_custom_log_levels()
command = flexmock()
flexmock(module).should_receive('make_repo_delete_command').and_return(command)
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
+36 -71
View File
@@ -23,7 +23,7 @@ def test_display_repository_info_calls_borg_with_flags():
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', '--json', '--repo', 'repo'),
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -31,7 +31,7 @@ def test_display_repository_info_calls_borg_with_flags():
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'repo-info', '--repo', 'repo'),
('borg', 'repo-info', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -59,7 +59,7 @@ def test_display_repository_info_without_borg_features_calls_borg_with_info_sub_
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', '--json', 'repo'),
('borg', 'repo-info', '--log-json', '--json', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -67,7 +67,7 @@ def test_display_repository_info_without_borg_features_calls_borg_with_info_sub_
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'info', 'repo'),
('borg', 'info', '--log-json', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -100,7 +100,7 @@ def test_display_repository_info_with_log_info_calls_borg_with_info_flag():
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', '--info', '--json', '--repo', 'repo'),
('borg', 'repo-info', '--info', '--log-json', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -108,7 +108,7 @@ def test_display_repository_info_with_log_info_calls_borg_with_info_flag():
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'repo-info', '--info', '--repo', 'repo'),
('borg', 'repo-info', '--info', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -141,7 +141,7 @@ def test_display_repository_info_with_log_info_and_json_suppresses_most_borg_out
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', '--json', '--repo', 'repo'),
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -177,7 +177,7 @@ def test_display_repository_info_with_log_debug_calls_borg_with_debug_flag():
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', '--debug', '--show-rc', '--json', '--repo', 'repo'),
('borg', 'repo-info', '--debug', '--show-rc', '--log-json', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -185,7 +185,7 @@ def test_display_repository_info_with_log_debug_calls_borg_with_debug_flag():
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'repo-info', '--debug', '--show-rc', '--repo', 'repo'),
('borg', 'repo-info', '--debug', '--show-rc', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -219,7 +219,7 @@ def test_display_repository_info_with_log_debug_and_json_suppresses_most_borg_ou
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', '--json', '--repo', 'repo'),
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -255,7 +255,7 @@ def test_display_repository_info_with_json_calls_borg_with_json_flag():
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', '--json', '--repo', 'repo'),
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -290,7 +290,7 @@ def test_display_repository_info_with_local_path_calls_borg_via_local_path():
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(
('borg1', 'repo-info', '--json', '--repo', 'repo'),
('borg1', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -298,7 +298,7 @@ def test_display_repository_info_with_local_path_calls_borg_via_local_path():
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg1', 'repo-info', '--repo', 'repo'),
('borg1', 'repo-info', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -333,7 +333,7 @@ def test_display_repository_info_with_exit_codes_calls_borg_using_them():
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
borg_exit_codes = flexmock()
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
('borg', 'repo-info', '--json', '--repo', 'repo'),
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -341,7 +341,7 @@ def test_display_repository_info_with_exit_codes_calls_borg_using_them():
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'repo-info', '--repo', 'repo'),
('borg', 'repo-info', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -374,7 +374,7 @@ def test_display_repository_info_with_remote_path_calls_borg_with_remote_path_fl
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', '--remote-path', 'borg1', '--json', '--repo', 'repo'),
('borg', 'repo-info', '--remote-path', 'borg1', '--log-json', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -382,7 +382,7 @@ def test_display_repository_info_with_remote_path_calls_borg_with_remote_path_fl
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'repo-info', '--remote-path', 'borg1', '--repo', 'repo'),
('borg', 'repo-info', '--remote-path', 'borg1', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -416,7 +416,7 @@ def test_display_repository_info_with_umask_calls_borg_with_umask_flags():
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', '--umask', '077', '--json', '--repo', 'repo'),
('borg', 'repo-info', '--umask', '077', '--log-json', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -424,7 +424,7 @@ def test_display_repository_info_with_umask_calls_borg_with_umask_flags():
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'repo-info', '--umask', '077', '--repo', 'repo'),
('borg', 'repo-info', '--umask', '077', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -442,50 +442,6 @@ def test_display_repository_info_with_umask_calls_borg_with_umask_flags():
)
def test_display_repository_info_with_log_json_calls_borg_with_log_json_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_flags').with_args('log-json', True).and_return(
('--log-json',),
)
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', '--log-json', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'repo-info', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
)
module.display_repository_info(
repository_path='repo',
config={'log_json': True},
local_borg_version='2.3.4',
repo_info_arguments=flexmock(json=False),
global_arguments=flexmock(),
)
def test_display_repository_info_with_lock_wait_calls_borg_with_lock_wait_flags():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
@@ -503,7 +459,7 @@ def test_display_repository_info_with_lock_wait_calls_borg_with_lock_wait_flags(
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', '--lock-wait', '5', '--json', '--repo', 'repo'),
('borg', 'repo-info', '--log-json', '--lock-wait', '5', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -511,7 +467,7 @@ def test_display_repository_info_with_lock_wait_calls_borg_with_lock_wait_flags(
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'repo-info', '--lock-wait', '5', '--repo', 'repo'),
('borg', 'repo-info', '--log-json', '--lock-wait', '5', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -545,7 +501,7 @@ def test_display_repository_info_without_feature_available_calls_borg_with_info_
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', 'info', '--extra', 'value with space', '--json', '--repo', 'repo'),
('borg', 'info', '--log-json', '--extra', 'value with space', '--json', '--repo', 'repo'),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -553,7 +509,7 @@ def test_display_repository_info_without_feature_available_calls_borg_with_info_
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'info', '--extra', 'value with space', '--repo', 'repo'),
('borg', 'info', '--log-json', '--extra', 'value with space', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -587,7 +543,16 @@ def test_display_repository_info_with_feature_available_calls_borg_with_repo_inf
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', '--extra', 'value with space', '--json', '--repo', 'repo'),
(
'borg',
'repo-info',
'--log-json',
'--extra',
'value with space',
'--json',
'--repo',
'repo',
),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -595,7 +560,7 @@ def test_display_repository_info_with_feature_available_calls_borg_with_repo_inf
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'repo-info', '--extra', 'value with space', '--repo', 'repo'),
('borg', 'repo-info', '--log-json', '--extra', 'value with space', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory=None,
@@ -630,7 +595,7 @@ def test_display_repository_info_calls_borg_with_working_directory():
'/working/dir',
)
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
('borg', 'repo-info', '--json', '--repo', 'repo'),
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
environment=None,
working_directory='/working/dir',
borg_local_path='borg',
@@ -638,7 +603,7 @@ def test_display_repository_info_calls_borg_with_working_directory():
).and_return('[]')
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'repo-info', '--repo', 'repo'),
('borg', 'repo-info', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
environment=None,
working_directory='/working/dir',
+40 -93
View File
@@ -119,7 +119,7 @@ def test_get_latest_archive_calls_borg_with_flags():
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', *BORG_LIST_LATEST_ARGUMENTS),
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
borg_local_path='borg',
borg_exit_codes=None,
environment=None,
@@ -148,7 +148,7 @@ def test_get_latest_archive_with_log_info_calls_borg_without_info_flag():
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', *BORG_LIST_LATEST_ARGUMENTS),
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -178,7 +178,7 @@ def test_get_latest_archive_with_log_debug_calls_borg_without_debug_flag():
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', *BORG_LIST_LATEST_ARGUMENTS),
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -208,7 +208,7 @@ def test_get_latest_archive_with_local_path_calls_borg_via_local_path():
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(
('borg1', 'list', *BORG_LIST_LATEST_ARGUMENTS),
('borg1', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
environment=None,
working_directory=None,
borg_local_path='borg1',
@@ -239,7 +239,7 @@ def test_get_latest_archive_with_exit_codes_calls_borg_using_them():
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
borg_exit_codes = flexmock()
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
('borg', 'list', *BORG_LIST_LATEST_ARGUMENTS),
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -271,7 +271,7 @@ def test_get_latest_archive_with_remote_path_calls_borg_with_remote_path_flags()
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', '--remote-path', 'borg1', *BORG_LIST_LATEST_ARGUMENTS),
('borg', 'list', '--remote-path', 'borg1', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -304,7 +304,7 @@ def test_get_latest_archive_with_umask_calls_borg_with_umask_flags():
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', '--umask', '077', *BORG_LIST_LATEST_ARGUMENTS),
('borg', 'list', '--umask', '077', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -332,7 +332,7 @@ def test_get_latest_archive_without_archives_raises():
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
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', *BORG_LIST_LATEST_ARGUMENTS),
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -348,38 +348,6 @@ def test_get_latest_archive_without_archives_raises():
)
def test_get_latest_archive_with_log_json_calls_borg_with_log_json_flag():
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('log-json', True).and_return(
('--log-json',)
)
flexmock(module.flags).should_receive('make_flags').with_args('last', 1).and_return(
('--last', '1')
)
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', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
environment=None,
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
).and_return(json.dumps({'archives': [expected_archive]}))
assert (
module.get_latest_archive(
'repo',
config={'log_json': True},
local_borg_version='1.2.3',
global_arguments=flexmock(),
)
== expected_archive
)
def test_get_latest_archive_with_lock_wait_calls_borg_with_lock_wait_flags():
expected_archive = {'name': 'archive-name', 'id': 'd34db33f'}
flexmock(module.feature).should_receive('available').and_return(False)
@@ -394,7 +362,7 @@ def test_get_latest_archive_with_lock_wait_calls_borg_with_lock_wait_flags():
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', '--lock-wait', 'okay', *BORG_LIST_LATEST_ARGUMENTS),
('borg', 'list', '--log-json', '--lock-wait', 'okay', *BORG_LIST_LATEST_ARGUMENTS),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -426,6 +394,7 @@ def test_get_latest_archive_calls_borg_with_list_extra_borg_options():
(
'borg',
'list',
'--log-json',
*BORG_LIST_LATEST_ARGUMENTS[:-1],
'--extra',
'value with space',
@@ -462,6 +431,7 @@ def test_get_latest_archive_with_feature_available_calls_borg_with_repo_list_ext
(
'borg',
'repo-list',
'--log-json',
*BORG_LIST_LATEST_ARGUMENTS[:-1],
'--extra',
'value with space',
@@ -498,7 +468,7 @@ def test_get_latest_archive_with_consider_checkpoints_calls_borg_with_consider_c
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', '--consider-checkpoints', *BORG_LIST_LATEST_ARGUMENTS),
('borg', 'list', '--log-json', '--consider-checkpoints', *BORG_LIST_LATEST_ARGUMENTS),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -531,7 +501,7 @@ def test_get_latest_archive_with_consider_checkpoints_and_feature_available_call
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-list', *BORG_REPO_LIST_LATEST_ARGUMENTS),
('borg', 'repo-list', '--log-json', *BORG_REPO_LIST_LATEST_ARGUMENTS),
environment=None,
working_directory=None,
borg_local_path='borg',
@@ -563,7 +533,7 @@ def test_get_latest_archive_calls_borg_with_working_directory():
'/working/dir',
)
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
('borg', 'list', *BORG_LIST_LATEST_ARGUMENTS),
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
borg_local_path='borg',
borg_exit_codes=None,
environment=None,
@@ -608,7 +578,7 @@ def test_make_repo_list_command_includes_log_info():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--info', 'repo')
assert command == ('borg', 'list', '--info', '--log-json', 'repo')
def test_make_repo_list_command_includes_json_but_not_info():
@@ -638,7 +608,7 @@ def test_make_repo_list_command_includes_json_but_not_info():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--json', 'repo')
assert command == ('borg', 'list', '--log-json', '--json', 'repo')
def test_make_repo_list_command_includes_log_debug():
@@ -668,7 +638,7 @@ def test_make_repo_list_command_includes_log_debug():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--debug', '--show-rc', 'repo')
assert command == ('borg', 'list', '--debug', '--show-rc', '--log-json', 'repo')
def test_make_repo_list_command_includes_json_but_not_debug():
@@ -698,7 +668,7 @@ def test_make_repo_list_command_includes_json_but_not_debug():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--json', 'repo')
assert command == ('borg', 'list', '--log-json', '--json', 'repo')
def test_make_repo_list_command_includes_json():
@@ -727,38 +697,7 @@ def test_make_repo_list_command_includes_json():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--json', 'repo')
def test_make_repo_list_command_includes_log_json():
flexmock(module.feature).should_receive('available').and_return(False)
flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(
('--log-json',),
).and_return(()).and_return(())
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',))
command = module.make_repo_list_command(
repository_path='repo',
config={'log_json': True},
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', '--log-json', 'repo')
assert command == ('borg', 'list', '--log-json', '--json', 'repo')
def test_make_repo_list_command_includes_lock_wait():
@@ -789,7 +728,7 @@ def test_make_repo_list_command_includes_lock_wait():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--lock-wait', '5', 'repo')
assert command == ('borg', 'list', '--lock-wait', '5', '--log-json', 'repo')
def test_make_repo_list_command_includes_list_extra_borg_options():
@@ -818,7 +757,7 @@ def test_make_repo_list_command_includes_list_extra_borg_options():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--extra', 'value with space', 'repo')
assert command == ('borg', 'list', '--log-json', '--extra', 'value with space', 'repo')
def test_make_repo_list_command_with_feature_available_includes_repo_list_extra_borg_options():
@@ -847,7 +786,7 @@ def test_make_repo_list_command_with_feature_available_includes_repo_list_extra_
global_arguments=flexmock(),
)
assert command == ('borg', 'repo-list', '--extra', 'value with space', 'repo')
assert command == ('borg', 'repo-list', '--log-json', '--extra', 'value with space', 'repo')
def test_make_repo_list_command_includes_local_path():
@@ -877,7 +816,7 @@ def test_make_repo_list_command_includes_local_path():
local_path='borg2',
)
assert command == ('borg2', 'list', 'repo')
assert command == ('borg2', 'list', '--log-json', 'repo')
def test_make_repo_list_command_includes_remote_path():
@@ -909,7 +848,7 @@ def test_make_repo_list_command_includes_remote_path():
remote_path='borg2',
)
assert command == ('borg', 'list', '--remote-path', 'borg2', 'repo')
assert command == ('borg', 'list', '--remote-path', 'borg2', '--log-json', 'repo')
def test_make_repo_list_command_includes_umask():
@@ -940,7 +879,7 @@ def test_make_repo_list_command_includes_umask():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--umask', '077', 'repo')
assert command == ('borg', 'list', '--umask', '077', '--log-json', 'repo')
def test_make_repo_list_command_transforms_prefix_into_match_archives():
@@ -966,7 +905,7 @@ def test_make_repo_list_command_transforms_prefix_into_match_archives():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--match-archives', 'sh:foo*', 'repo')
assert command == ('borg', 'list', '--log-json', '--match-archives', 'sh:foo*', 'repo')
def test_make_repo_list_command_prefers_prefix_over_archive_name_format():
@@ -988,7 +927,7 @@ def test_make_repo_list_command_prefers_prefix_over_archive_name_format():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--match-archives', 'sh:foo*', 'repo')
assert command == ('borg', 'list', '--log-json', '--match-archives', 'sh:foo*', 'repo')
def test_make_repo_list_command_transforms_archive_name_format_into_match_archives():
@@ -1017,7 +956,7 @@ def test_make_repo_list_command_transforms_archive_name_format_into_match_archiv
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--match-archives', 'sh:bar-*', 'repo')
assert command == ('borg', 'list', '--log-json', '--match-archives', 'sh:bar-*', 'repo')
def test_make_repo_list_command_includes_format_from_command_line():
@@ -1049,7 +988,7 @@ def test_make_repo_list_command_includes_format_from_command_line():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--format', 'stuff', 'repo')
assert command == ('borg', 'list', '--log-json', '--format', 'stuff', 'repo')
def test_make_repo_list_command_includes_short():
@@ -1079,7 +1018,7 @@ def test_make_repo_list_command_includes_short():
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--short', 'repo')
assert command == ('borg', 'list', '--log-json', '--short', 'repo')
@pytest.mark.parametrize(
@@ -1124,7 +1063,14 @@ def test_make_repo_list_command_includes_additional_flags(argument_name):
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--' + argument_name.replace('_', '-'), 'value', 'repo')
assert command == (
'borg',
'list',
'--log-json',
'--' + argument_name.replace('_', '-'),
'value',
'repo',
)
def test_make_repo_list_command_with_match_archives_calls_borg_with_match_archives_flags():
@@ -1159,7 +1105,7 @@ def test_make_repo_list_command_with_match_archives_calls_borg_with_match_archiv
global_arguments=flexmock(),
)
assert command == ('borg', 'list', '--match-archives', 'foo-*', 'repo')
assert command == ('borg', 'list', '--log-json', '--match-archives', 'foo-*', 'repo')
def test_list_repository_calls_two_commands():
@@ -1238,6 +1184,7 @@ def test_make_repo_list_command_with_date_based_matching_calls_borg_with_date_ba
assert command == (
'borg',
'list',
'--log-json',
'--newer',
'1d',
'--newest',
+54 -53
View File
@@ -18,7 +18,7 @@ def test_transfer_archives_calls_borg_with_flags():
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', '--repo', 'repo'),
('borg', 'transfer', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -55,7 +55,7 @@ def test_transfer_archives_with_dry_run_calls_borg_with_dry_run_flag():
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', '--repo', 'repo', '--dry-run'),
('borg', 'transfer', '--log-json', '--repo', 'repo', '--dry-run'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -89,7 +89,7 @@ def test_transfer_archives_with_log_info_calls_borg_with_info_flag():
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', '--info', '--repo', 'repo'),
('borg', 'transfer', '--info', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -123,7 +123,7 @@ def test_transfer_archives_with_log_debug_calls_borg_with_debug_flag():
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', '--debug', '--show-rc', '--repo', 'repo'),
('borg', 'transfer', '--debug', '--show-rc', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -162,7 +162,7 @@ def test_transfer_archives_with_archive_calls_borg_with_match_archives_flag():
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', '--match-archives', 'archive', '--repo', 'repo'),
('borg', 'transfer', '--log-json', '--match-archives', 'archive', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -200,7 +200,7 @@ def test_transfer_archives_with_match_archives_calls_borg_with_match_archives_fl
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', '--match-archives', 'sh:foo*', '--repo', 'repo'),
('borg', 'transfer', '--log-json', '--match-archives', 'sh:foo*', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -238,7 +238,7 @@ def test_transfer_archives_with_archive_name_format_calls_borg_with_match_archiv
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', '--match-archives', 'sh:bar-*', '--repo', 'repo'),
('borg', 'transfer', '--log-json', '--match-archives', 'sh:bar-*', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -272,7 +272,7 @@ def test_transfer_archives_with_local_path_calls_borg_via_local_path():
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(
('borg2', 'transfer', '--repo', 'repo'),
('borg2', 'transfer', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -308,7 +308,7 @@ def test_transfer_archives_with_exit_codes_calls_borg_using_them():
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
borg_exit_codes = flexmock()
flexmock(module).should_receive('execute_command').with_args(
('borg', 'transfer', '--repo', 'repo'),
('borg', 'transfer', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -346,7 +346,7 @@ def test_transfer_archives_with_remote_path_calls_borg_with_remote_path_flags():
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', '--remote-path', 'borg2', '--repo', 'repo'),
('borg', 'transfer', '--remote-path', 'borg2', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -383,7 +383,7 @@ def test_transfer_archives_with_umask_calls_borg_with_umask_flags():
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', '--umask', '077', '--repo', 'repo'),
('borg', 'transfer', '--umask', '077', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -407,43 +407,6 @@ def test_transfer_archives_with_umask_calls_borg_with_umask_flags():
)
def test_transfer_archives_with_log_json_calls_borg_with_log_json_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('log-json', True).and_return(
('--log-json',),
)
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', '--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,
)
module.transfer_archives(
dry_run=False,
repository_path='repo',
config={'log_json': True},
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_lock_wait_calls_borg_with_lock_wait_flags():
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
@@ -458,7 +421,7 @@ def test_transfer_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
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', '--lock-wait', '5', '--repo', 'repo'),
('borg', 'transfer', '--log-json', '--lock-wait', '5', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -493,7 +456,7 @@ def test_transfer_archives_calls_borg_with_extra_borg_options():
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', '--extra', 'value with space', '--repo', 'repo'),
('borg', 'transfer', '--log-json', '--extra', 'value with space', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -554,6 +517,43 @@ def test_transfer_archives_with_progress_calls_borg_with_progress_flags():
)
def test_transfer_archives_with_log_json_and_progress_calls_borg_with_both_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('progress', True).and_return(
('--progress',),
)
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', '--log-json', '--progress', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=module.DO_NOT_CAPTURE,
environment=None,
working_directory=None,
borg_local_path='borg',
borg_exit_codes=None,
)
module.transfer_archives(
dry_run=False,
repository_path='repo',
config={'log_json': True, 'progress': True},
local_borg_version='2.3.4',
transfer_arguments=flexmock(
archive=None,
progress=None,
match_archives=None,
source_repository=None,
),
global_arguments=flexmock(),
)
@pytest.mark.parametrize('argument_name', ('upgrader', 'sort_by', 'first', 'last'))
def test_transfer_archives_passes_through_arguments_to_borg(argument_name):
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
@@ -568,7 +568,7 @@ def test_transfer_archives_passes_through_arguments_to_borg(argument_name):
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', flag_name, 'value', '--repo', 'repo'),
('borg', 'transfer', '--log-json', flag_name, 'value', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -605,7 +605,7 @@ def test_transfer_archives_with_source_repository_calls_borg_with_other_repo_fla
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', '--repo', 'repo', '--other-repo', 'other'),
('borg', 'transfer', '--log-json', '--repo', 'repo', '--other-repo', 'other'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
@@ -643,6 +643,7 @@ def test_transfer_archives_with_date_based_matching_calls_borg_with_date_based_f
(
'borg',
'transfer',
'--log-json',
'--newer',
'1d',
'--newest',
@@ -692,7 +693,7 @@ def test_transfer_archives_calls_borg_with_working_directory():
'/working/dir',
)
flexmock(module).should_receive('execute_command').with_args(
('borg', 'transfer', '--repo', 'repo'),
('borg', 'transfer', '--log-json', '--repo', 'repo'),
output_log_level=module.borgmatic.logger.ANSWER,
output_file=None,
environment=None,
+12 -7
View File
@@ -25,20 +25,20 @@ def insert_execute_command_mock(
def test_unmount_archive_calls_borg_with_required_parameters():
insert_execute_command_mock(('borg', 'umount', '/mnt'))
insert_execute_command_mock(('borg', 'umount', '--log-json', '/mnt'))
module.unmount_archive(config={}, mount_point='/mnt')
def test_unmount_archive_with_log_info_calls_borg_with_info_parameter():
insert_execute_command_mock(('borg', 'umount', '--info', '/mnt'))
insert_execute_command_mock(('borg', 'umount', '--log-json', '--info', '/mnt'))
insert_logging_mock(logging.INFO)
module.unmount_archive(config={}, mount_point='/mnt')
def test_unmount_archive_with_log_debug_calls_borg_with_debug_parameters():
insert_execute_command_mock(('borg', 'umount', '--debug', '--show-rc', '/mnt'))
insert_execute_command_mock(('borg', 'umount', '--log-json', '--debug', '--show-rc', '/mnt'))
insert_logging_mock(logging.DEBUG)
module.unmount_archive(config={}, mount_point='/mnt')
@@ -46,7 +46,8 @@ def test_unmount_archive_with_log_debug_calls_borg_with_debug_parameters():
def test_unmount_archive_calls_borg_with_extra_borg_options():
insert_execute_command_mock(
('borg', 'umount', '--extra', 'value with space', '/mnt'), borg_local_path='borg'
('borg', 'umount', '--log-json', '--extra', 'value with space', '/mnt'),
borg_local_path='borg',
)
module.unmount_archive(
@@ -55,19 +56,23 @@ def test_unmount_archive_calls_borg_with_extra_borg_options():
def test_unmount_archive_calls_borg_with_local_path():
insert_execute_command_mock(('borg1', 'umount', '/mnt'), borg_local_path='borg1')
insert_execute_command_mock(('borg1', 'umount', '--log-json', '/mnt'), borg_local_path='borg1')
module.unmount_archive(config={}, mount_point='/mnt', local_path='borg1')
def test_unmount_archive_calls_borg_with_exit_codes():
borg_exit_codes = flexmock()
insert_execute_command_mock(('borg', 'umount', '/mnt'), borg_exit_codes=borg_exit_codes)
insert_execute_command_mock(
('borg', 'umount', '--log-json', '/mnt'), borg_exit_codes=borg_exit_codes
)
module.unmount_archive(config={'borg_exit_codes': borg_exit_codes}, mount_point='/mnt')
def test_unmount_archive_calls_borg_with_working_directory():
insert_execute_command_mock(('borg', 'umount', '/mnt'), working_directory='/working/dir')
insert_execute_command_mock(
('borg', 'umount', '--log-json', '/mnt'), working_directory='/working/dir'
)
module.unmount_archive(config={'working_directory': '/working/dir'}, mount_point='/mnt')
+9 -9
View File
@@ -86,45 +86,45 @@ def test_output_buffer_for_process_returns_stdout_when_not_excluded():
)
def test_append_last_lines_under_max_line_count_appends():
def test_log_line_under_max_line_count_appends():
last_lines = ['last']
flexmock(module.logger).should_receive('log').once()
module.append_last_lines(
module.log_line(
last_lines,
captured_output=flexmock(),
line='line',
log_level=flexmock(),
default_log_level=flexmock(),
)
assert last_lines == ['last', 'line']
def test_append_last_lines_over_max_line_count_trims_and_appends():
def test_log_line_over_max_line_count_trims_and_appends():
original_last_lines = [str(number) for number in range(module.ERROR_OUTPUT_MAX_LINE_COUNT)]
last_lines = list(original_last_lines)
flexmock(module.logger).should_receive('log').once()
module.append_last_lines(
module.log_line(
last_lines,
captured_output=flexmock(),
line='line',
log_level=flexmock(),
default_log_level=flexmock(),
)
assert last_lines == [*original_last_lines[1:], 'line']
def test_append_last_lines_with_output_log_level_none_appends_captured_output():
def test_log_line_with_output_log_level_none_appends_captured_output():
last_lines = ['last']
captured_output = ['captured']
flexmock(module.logger).should_receive('log').never()
module.append_last_lines(
module.log_line(
last_lines,
captured_output=captured_output,
line='line',
log_level=None,
default_log_level=None,
)
assert captured_output == ['captured', 'line']