2023-01-26 08:31:07 +01:00
|
|
|
from flexmock import flexmock
|
|
|
|
|
|
|
|
from borgmatic.actions import create as module
|
|
|
|
|
|
|
|
|
2023-03-16 19:01:29 +01:00
|
|
|
def test_run_create_executes_and_calls_hooks_for_configured_repository():
|
2023-01-26 08:31:07 +01:00
|
|
|
flexmock(module.logger).answer = lambda message: None
|
2023-03-16 19:01:29 +01:00
|
|
|
flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never()
|
2023-03-16 18:15:49 +01:00
|
|
|
flexmock(module.borgmatic.borg.create).should_receive('create_archive').once()
|
2023-01-26 08:31:07 +01:00
|
|
|
flexmock(module.borgmatic.hooks.command).should_receive('execute_hook').times(2)
|
|
|
|
flexmock(module.borgmatic.hooks.dispatch).should_receive('call_hooks').and_return({})
|
|
|
|
flexmock(module.borgmatic.hooks.dispatch).should_receive(
|
|
|
|
'call_hooks_even_if_unconfigured'
|
|
|
|
).and_return({})
|
|
|
|
create_arguments = flexmock(
|
2023-03-16 19:01:29 +01:00
|
|
|
repository=None,
|
2023-03-16 18:15:49 +01:00
|
|
|
progress=flexmock(),
|
|
|
|
stats=flexmock(),
|
|
|
|
json=flexmock(),
|
|
|
|
list_files=flexmock(),
|
|
|
|
)
|
2023-05-16 19:47:35 +02:00
|
|
|
global_arguments = flexmock(monitoring_verbosity=1, dry_run=False, used_config_paths=[])
|
2023-03-16 18:15:49 +01:00
|
|
|
|
|
|
|
list(
|
|
|
|
module.run_create(
|
|
|
|
config_filename='test.yaml',
|
2023-03-24 20:34:57 +01:00
|
|
|
repository={'path': 'repo'},
|
2023-03-16 18:15:49 +01:00
|
|
|
location={},
|
|
|
|
storage={},
|
|
|
|
hooks={},
|
|
|
|
hook_context={},
|
|
|
|
local_borg_version=None,
|
|
|
|
create_arguments=create_arguments,
|
|
|
|
global_arguments=global_arguments,
|
|
|
|
dry_run_label='',
|
|
|
|
local_path=None,
|
|
|
|
remote_path=None,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-03-16 21:27:08 +01:00
|
|
|
def test_run_create_runs_with_selected_repository():
|
2023-03-16 18:15:49 +01:00
|
|
|
flexmock(module.logger).answer = lambda message: None
|
|
|
|
flexmock(module.borgmatic.config.validate).should_receive(
|
|
|
|
'repositories_match'
|
|
|
|
).once().and_return(True)
|
|
|
|
flexmock(module.borgmatic.borg.create).should_receive('create_archive').once()
|
|
|
|
create_arguments = flexmock(
|
|
|
|
repository=flexmock(),
|
|
|
|
progress=flexmock(),
|
|
|
|
stats=flexmock(),
|
|
|
|
json=flexmock(),
|
|
|
|
list_files=flexmock(),
|
|
|
|
)
|
2023-05-16 19:47:35 +02:00
|
|
|
global_arguments = flexmock(monitoring_verbosity=1, dry_run=False, used_config_paths=[])
|
2023-03-16 18:15:49 +01:00
|
|
|
|
|
|
|
list(
|
|
|
|
module.run_create(
|
|
|
|
config_filename='test.yaml',
|
2023-03-24 20:34:57 +01:00
|
|
|
repository={'path': 'repo'},
|
2023-03-16 18:15:49 +01:00
|
|
|
location={},
|
|
|
|
storage={},
|
|
|
|
hooks={},
|
|
|
|
hook_context={},
|
|
|
|
local_borg_version=None,
|
|
|
|
create_arguments=create_arguments,
|
|
|
|
global_arguments=global_arguments,
|
|
|
|
dry_run_label='',
|
|
|
|
local_path=None,
|
|
|
|
remote_path=None,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_run_create_bails_if_repository_does_not_match():
|
|
|
|
flexmock(module.logger).answer = lambda message: None
|
|
|
|
flexmock(module.borgmatic.config.validate).should_receive(
|
|
|
|
'repositories_match'
|
|
|
|
).once().and_return(False)
|
|
|
|
flexmock(module.borgmatic.borg.create).should_receive('create_archive').never()
|
|
|
|
create_arguments = flexmock(
|
|
|
|
repository=flexmock(),
|
|
|
|
progress=flexmock(),
|
|
|
|
stats=flexmock(),
|
|
|
|
json=flexmock(),
|
|
|
|
list_files=flexmock(),
|
2023-01-26 08:31:07 +01:00
|
|
|
)
|
2023-05-16 19:47:35 +02:00
|
|
|
global_arguments = flexmock(monitoring_verbosity=1, dry_run=False, used_config_paths=[])
|
2023-01-26 08:31:07 +01:00
|
|
|
|
|
|
|
list(
|
|
|
|
module.run_create(
|
|
|
|
config_filename='test.yaml',
|
|
|
|
repository='repo',
|
|
|
|
location={},
|
|
|
|
storage={},
|
|
|
|
hooks={},
|
|
|
|
hook_context={},
|
|
|
|
local_borg_version=None,
|
|
|
|
create_arguments=create_arguments,
|
|
|
|
global_arguments=global_arguments,
|
|
|
|
dry_run_label='',
|
|
|
|
local_path=None,
|
|
|
|
remote_path=None,
|
|
|
|
)
|
|
|
|
)
|