mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-08-01 14:13:01 +02:00
add tests and requested changes
This commit is contained in:
@@ -27,10 +27,9 @@ def run_recreate(
|
||||
else:
|
||||
logger.info('Recreating repository')
|
||||
|
||||
# collect and process patterns
|
||||
patterns = collect_patterns(config)
|
||||
# Collect and process patterns.
|
||||
processed_patterns = process_patterns(
|
||||
patterns, borgmatic.config.paths.get_working_directory(config)
|
||||
collect_patterns(config), borgmatic.config.paths.get_working_directory(config)
|
||||
)
|
||||
|
||||
borgmatic.borg.recreate.recreate_archive(
|
||||
|
||||
@@ -3,8 +3,8 @@ import logging
|
||||
import borgmatic.borg.environment
|
||||
import borgmatic.config.paths
|
||||
import borgmatic.execute
|
||||
from borgmatic.borg.create import make_exclude_flags
|
||||
from borgmatic.borg.flags import make_flags_from_arguments, make_repository_archive_flags
|
||||
from borgmatic.borg.create import make_exclude_flags, write_patterns_file, make_list_filter_flags
|
||||
from borgmatic.borg.flags import make_repository_archive_flags
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -31,20 +31,31 @@ def recreate_archive(
|
||||
|
||||
repo_archive_arg = make_repository_archive_flags(repository, archive, local_borg_version)
|
||||
exclude_flags = make_exclude_flags(config)
|
||||
# handle path from recreate_arguments
|
||||
path_flag = ('--path', recreate_arguments.path) if recreate_arguments.path else ()
|
||||
pattern_flags = ('--patterns-from', patterns) if patterns else ()
|
||||
|
||||
# Write patterns to a temporary file and use that file with --patterns-from.
|
||||
patterns_file = write_patterns_file(
|
||||
patterns, borgmatic.config.paths.get_working_directory(config)
|
||||
)
|
||||
|
||||
recreate_cmd = (
|
||||
(local_path, 'recreate')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ repo_archive_arg
|
||||
+ path_flag
|
||||
+ (('--path', recreate_arguments.path) if recreate_arguments.path else ())
|
||||
+ (('--log-json',) if global_arguments.log_json else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc', '--list') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ pattern_flags
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ (('--patterns-from', patterns_file.name) if patterns_file else ())
|
||||
+ (
|
||||
(
|
||||
'--list',
|
||||
'--filter',
|
||||
make_list_filter_flags(local_borg_version, global_arguments.dry_run),
|
||||
)
|
||||
if recreate_arguments.list
|
||||
else ()
|
||||
)
|
||||
+ exclude_flags
|
||||
)
|
||||
|
||||
@@ -54,7 +65,7 @@ def recreate_archive(
|
||||
|
||||
borgmatic.execute.execute_command(
|
||||
recreate_cmd,
|
||||
output_log_level=logging.ANSWER,
|
||||
output_log_level=logging.INFO,
|
||||
environment=borgmatic.borg.environment.make_environment(config),
|
||||
working_directory=borgmatic.config.paths.get_working_directory(config),
|
||||
remote_path=remote_path,
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.actions import recreate as module
|
||||
|
||||
|
||||
def test_run_recreate_does_not_raise():
|
||||
flexmock(module.logger).answer = lambda message: None
|
||||
flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True)
|
||||
flexmock(module.borgmatic.borg.recreate).should_receive('recreate_archive')
|
||||
|
||||
recreate_arguments = flexmock(repository=flexmock(), archive=None)
|
||||
|
||||
module.run_recreate(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=None,
|
||||
recreate_arguments=recreate_arguments,
|
||||
global_arguments=flexmock(),
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
|
||||
def test_run_recreate_with_archive_does_not_raise():
|
||||
flexmock(module.logger).answer = lambda message: None
|
||||
flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True)
|
||||
flexmock(module.borgmatic.borg.recreate).should_receive('recreate_archive')
|
||||
|
||||
recreate_arguments = flexmock(repository=flexmock(), archive='test-archive')
|
||||
|
||||
module.run_recreate(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=None,
|
||||
recreate_arguments=recreate_arguments,
|
||||
global_arguments=flexmock(),
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
@@ -1019,6 +1019,27 @@ def test_run_actions_runs_create():
|
||||
assert result == (expected,)
|
||||
|
||||
|
||||
def test_run_actions_runs_recreate():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module).should_receive('get_skip_actions').and_return([])
|
||||
flexmock(module.command).should_receive('Before_after_hooks').and_return(flexmock())
|
||||
|
||||
flexmock(borgmatic.actions.recreate).should_receive('run_recreate').once()
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'recreate': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
config={'repositories': []},
|
||||
config_paths=[],
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
repository={'path': 'repo'},
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_run_actions_with_skip_actions_skips_create():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module).should_receive('get_skip_actions').and_return(['create'])
|
||||
|
||||
Reference in New Issue
Block a user