2020-01-23 22:41:37 +01:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from borgmatic.config import normalize as module
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2022-08-17 19:13:11 +02:00
|
|
|
'config,expected_config,produces_logs',
|
2020-01-23 22:41:37 +01:00
|
|
|
(
|
|
|
|
(
|
|
|
|
{'location': {'exclude_if_present': '.nobackup'}},
|
|
|
|
{'location': {'exclude_if_present': ['.nobackup']}},
|
2022-08-17 19:13:11 +02:00
|
|
|
False,
|
2020-01-23 22:41:37 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
{'location': {'exclude_if_present': ['.nobackup']}},
|
|
|
|
{'location': {'exclude_if_present': ['.nobackup']}},
|
2022-08-17 19:13:11 +02:00
|
|
|
False,
|
2020-01-23 22:41:37 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
{'location': {'source_directories': ['foo', 'bar']}},
|
|
|
|
{'location': {'source_directories': ['foo', 'bar']}},
|
2022-08-17 19:13:11 +02:00
|
|
|
False,
|
|
|
|
),
|
2022-10-23 22:56:03 +02:00
|
|
|
({'location': None}, {'location': None}, False,),
|
2022-08-17 19:13:11 +02:00
|
|
|
(
|
|
|
|
{'storage': {'compression': 'yes_please'}},
|
|
|
|
{'storage': {'compression': 'yes_please'}},
|
|
|
|
False,
|
2020-01-23 22:41:37 +01:00
|
|
|
),
|
2022-10-23 22:56:03 +02:00
|
|
|
({'storage': None}, {'storage': None}, False,),
|
2022-05-24 05:02:10 +02:00
|
|
|
(
|
|
|
|
{'hooks': {'healthchecks': 'https://example.com'}},
|
|
|
|
{'hooks': {'healthchecks': {'ping_url': 'https://example.com'}}},
|
2022-08-17 19:13:11 +02:00
|
|
|
False,
|
2022-05-24 05:02:10 +02:00
|
|
|
),
|
|
|
|
(
|
|
|
|
{'hooks': {'cronitor': 'https://example.com'}},
|
|
|
|
{'hooks': {'cronitor': {'ping_url': 'https://example.com'}}},
|
2022-08-17 19:13:11 +02:00
|
|
|
False,
|
2022-05-24 05:02:10 +02:00
|
|
|
),
|
|
|
|
(
|
|
|
|
{'hooks': {'pagerduty': 'https://example.com'}},
|
|
|
|
{'hooks': {'pagerduty': {'integration_key': 'https://example.com'}}},
|
2022-08-17 19:13:11 +02:00
|
|
|
False,
|
2022-05-24 05:02:10 +02:00
|
|
|
),
|
|
|
|
(
|
|
|
|
{'hooks': {'cronhub': 'https://example.com'}},
|
|
|
|
{'hooks': {'cronhub': {'ping_url': 'https://example.com'}}},
|
2022-08-17 19:13:11 +02:00
|
|
|
False,
|
2022-05-24 05:02:10 +02:00
|
|
|
),
|
2022-10-23 22:56:03 +02:00
|
|
|
({'hooks': None}, {'hooks': None}, False,),
|
2022-05-28 23:42:19 +02:00
|
|
|
(
|
|
|
|
{'consistency': {'checks': ['archives']}},
|
|
|
|
{'consistency': {'checks': [{'name': 'archives'}]}},
|
2022-08-17 19:13:11 +02:00
|
|
|
False,
|
|
|
|
),
|
2022-10-23 22:56:03 +02:00
|
|
|
(
|
|
|
|
{'consistency': {'checks': ['archives']}},
|
|
|
|
{'consistency': {'checks': [{'name': 'archives'}]}},
|
|
|
|
False,
|
|
|
|
),
|
|
|
|
({'consistency': None}, {'consistency': None}, False,),
|
2022-08-18 06:14:58 +02:00
|
|
|
({'location': {'numeric_owner': False}}, {'location': {'numeric_ids': False}}, False,),
|
|
|
|
({'location': {'bsd_flags': False}}, {'location': {'flags': False}}, False,),
|
|
|
|
(
|
|
|
|
{'storage': {'remote_rate_limit': False}},
|
|
|
|
{'storage': {'upload_rate_limit': False}},
|
|
|
|
False,
|
|
|
|
),
|
2022-08-17 19:13:11 +02:00
|
|
|
(
|
|
|
|
{'location': {'repositories': ['foo@bar:/repo']}},
|
2023-03-24 20:34:57 +01:00
|
|
|
{'location': {'repositories': [{'path': 'ssh://foo@bar/repo', 'label': ''}]}},
|
2022-08-17 19:13:11 +02:00
|
|
|
True,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
{'location': {'repositories': ['foo@bar:repo']}},
|
2023-03-24 20:34:57 +01:00
|
|
|
{'location': {'repositories': [{'path': 'ssh://foo@bar/./repo', 'label': ''}]}},
|
2022-08-17 19:13:11 +02:00
|
|
|
True,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
{'location': {'repositories': ['foo@bar:~/repo']}},
|
2023-03-24 20:34:57 +01:00
|
|
|
{'location': {'repositories': [{'path': 'ssh://foo@bar/~/repo', 'label': ''}]}},
|
2022-08-17 19:13:11 +02:00
|
|
|
True,
|
|
|
|
),
|
|
|
|
(
|
2022-08-18 06:54:00 +02:00
|
|
|
{'location': {'repositories': ['ssh://foo@bar:1234/repo']}},
|
2023-03-24 20:34:57 +01:00
|
|
|
{'location': {'repositories': [{'path': 'ssh://foo@bar:1234/repo', 'label': ''}]}},
|
2022-08-17 19:13:11 +02:00
|
|
|
False,
|
2022-05-28 23:42:19 +02:00
|
|
|
),
|
2023-03-21 12:36:03 +01:00
|
|
|
(
|
|
|
|
{'location': {'repositories': ['file:///repo']}},
|
2023-03-24 20:34:57 +01:00
|
|
|
{'location': {'repositories': [{'path': '/repo', 'label': ''}]}},
|
2023-03-21 12:36:03 +01:00
|
|
|
False,
|
|
|
|
),
|
2020-01-23 22:41:37 +01:00
|
|
|
),
|
|
|
|
)
|
2022-08-17 19:13:11 +02:00
|
|
|
def test_normalize_applies_hard_coded_normalization_to_config(
|
|
|
|
config, expected_config, produces_logs
|
|
|
|
):
|
|
|
|
logs = module.normalize('test.yaml', config)
|
2020-01-23 22:41:37 +01:00
|
|
|
|
|
|
|
assert config == expected_config
|
2022-08-17 19:13:11 +02:00
|
|
|
|
|
|
|
if produces_logs:
|
|
|
|
assert logs
|
|
|
|
else:
|
|
|
|
assert logs == []
|