2023-06-11 00:50:11 +02:00
|
|
|
import pytest
|
2023-06-06 22:13:01 +02:00
|
|
|
from flexmock import flexmock
|
|
|
|
|
|
|
|
from borgmatic.actions.config import bootstrap as module
|
|
|
|
|
|
|
|
|
2023-06-07 20:26:02 +02:00
|
|
|
def test_get_config_paths_returns_list_of_config_paths():
|
2023-06-06 22:13:01 +02:00
|
|
|
bootstrap_arguments = flexmock(
|
2023-06-07 20:26:02 +02:00
|
|
|
borgmatic_source_directory=None,
|
2023-06-06 22:13:01 +02:00
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
)
|
|
|
|
global_arguments = flexmock(
|
|
|
|
dry_run=False,
|
|
|
|
)
|
|
|
|
local_borg_version = flexmock()
|
|
|
|
extract_process = flexmock(
|
|
|
|
stdout=flexmock(
|
|
|
|
read=lambda: '{"config_paths": ["/borgmatic/config.yaml"]}',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
flexmock(module.borgmatic.borg.extract).should_receive('extract_archive').and_return(
|
|
|
|
extract_process
|
|
|
|
)
|
|
|
|
flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name').and_return(
|
|
|
|
'archive'
|
|
|
|
)
|
2023-06-07 20:37:36 +02:00
|
|
|
assert module.get_config_paths(bootstrap_arguments, global_arguments, local_borg_version) == [
|
|
|
|
'/borgmatic/config.yaml'
|
|
|
|
]
|
2023-06-07 20:26:02 +02:00
|
|
|
|
|
|
|
|
2023-06-11 00:50:11 +02:00
|
|
|
def test_get_config_paths_with_missing_manifest_raises_value_error():
|
|
|
|
bootstrap_arguments = flexmock(
|
|
|
|
borgmatic_source_directory=None,
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
)
|
|
|
|
global_arguments = flexmock(
|
|
|
|
dry_run=False,
|
|
|
|
)
|
|
|
|
local_borg_version = flexmock()
|
|
|
|
extract_process = flexmock(stdout=flexmock(read=lambda: ''))
|
|
|
|
flexmock(module.borgmatic.borg.extract).should_receive('extract_archive').and_return(
|
|
|
|
extract_process
|
|
|
|
)
|
|
|
|
flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name').and_return(
|
|
|
|
'archive'
|
|
|
|
)
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.get_config_paths(bootstrap_arguments, global_arguments, local_borg_version)
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_config_paths_with_broken_json_raises_value_error():
|
|
|
|
bootstrap_arguments = flexmock(
|
|
|
|
borgmatic_source_directory=None,
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
)
|
|
|
|
global_arguments = flexmock(
|
|
|
|
dry_run=False,
|
|
|
|
)
|
|
|
|
local_borg_version = flexmock()
|
|
|
|
extract_process = flexmock(
|
|
|
|
stdout=flexmock(read=lambda: '{"config_paths": ["/oops'),
|
|
|
|
)
|
|
|
|
flexmock(module.borgmatic.borg.extract).should_receive('extract_archive').and_return(
|
|
|
|
extract_process
|
|
|
|
)
|
|
|
|
flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name').and_return(
|
|
|
|
'archive'
|
|
|
|
)
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.get_config_paths(bootstrap_arguments, global_arguments, local_borg_version)
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_config_paths_with_json_missing_key_raises_value_error():
|
|
|
|
bootstrap_arguments = flexmock(
|
|
|
|
borgmatic_source_directory=None,
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
)
|
|
|
|
global_arguments = flexmock(
|
|
|
|
dry_run=False,
|
|
|
|
)
|
|
|
|
local_borg_version = flexmock()
|
|
|
|
extract_process = flexmock(
|
|
|
|
stdout=flexmock(read=lambda: '{}'),
|
|
|
|
)
|
|
|
|
flexmock(module.borgmatic.borg.extract).should_receive('extract_archive').and_return(
|
|
|
|
extract_process
|
|
|
|
)
|
|
|
|
flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name').and_return(
|
|
|
|
'archive'
|
|
|
|
)
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.get_config_paths(bootstrap_arguments, global_arguments, local_borg_version)
|
|
|
|
|
|
|
|
|
2023-06-07 20:26:02 +02:00
|
|
|
def test_run_bootstrap_does_not_raise():
|
|
|
|
bootstrap_arguments = flexmock(
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
destination='dest',
|
|
|
|
strip_components=1,
|
|
|
|
progress=False,
|
|
|
|
borgmatic_source_directory='/borgmatic',
|
|
|
|
)
|
|
|
|
global_arguments = flexmock(
|
|
|
|
dry_run=False,
|
|
|
|
)
|
|
|
|
local_borg_version = flexmock()
|
|
|
|
extract_process = flexmock(
|
|
|
|
stdout=flexmock(
|
|
|
|
read=lambda: '{"config_paths": ["/borgmatic/config.yaml"]}',
|
|
|
|
),
|
|
|
|
)
|
2023-06-06 22:13:01 +02:00
|
|
|
flexmock(module.borgmatic.borg.extract).should_receive('extract_archive').and_return(
|
|
|
|
extract_process
|
2023-06-07 20:26:02 +02:00
|
|
|
).twice()
|
|
|
|
flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name').and_return(
|
|
|
|
'archive'
|
2023-06-06 22:13:01 +02:00
|
|
|
)
|
2023-06-21 21:19:49 +02:00
|
|
|
|
2023-06-06 22:13:01 +02:00
|
|
|
module.run_bootstrap(bootstrap_arguments, global_arguments, local_borg_version)
|