add tests for repo labels

This commit is contained in:
Divyansh Singh 2023-03-27 00:19:23 +05:30
parent ec9def4e71
commit b336b9bedf
2 changed files with 37 additions and 0 deletions

View file

@ -92,6 +92,21 @@ from borgmatic.config import normalize as module
{'location': {'repositories': [{'path': '/repo'}]}}, {'location': {'repositories': [{'path': '/repo'}]}},
False, False,
), ),
(
{'location': {'repositories': [{'path': 'foo@bar:/repo', 'label': 'foo'}]}},
{'location': {'repositories': [{'path': 'ssh://foo@bar/repo', 'label': 'foo'}]}},
True,
),
(
{'location': {'repositories': [{'path': 'file:///repo', 'label': 'foo'}]}},
{'location': {'repositories': [{'path': '/repo', 'label': 'foo'}]}},
False,
),
(
{'location': {'repositories': [{'path': '/repo', 'label': 'foo'}]}},
{'location': {'repositories': [{'path': '/repo', 'label': 'foo'}]}},
False,
),
), ),
) )
def test_normalize_applies_hard_coded_normalization_to_config( def test_normalize_applies_hard_coded_normalization_to_config(
@ -105,3 +120,15 @@ def test_normalize_applies_hard_coded_normalization_to_config(
assert logs assert logs
else: else:
assert logs == [] assert logs == []
def test_normalize_raises_error_if_repository_data_is_not_consistent():
with pytest.raises(TypeError):
module.normalize(
'test.yaml',
{
'location': {
'repositories': [{'path': 'foo@bar:/repo', 'label': 'foo'}, 'file:///repo']
}
},
)

View file

@ -121,6 +121,16 @@ def test_guard_configuration_contains_repository_does_not_raise_when_repository_
) )
def test_guard_configuration_contains_repository_does_not_raise_when_repository_label_in_config():
module.guard_configuration_contains_repository(
repository='repo',
configurations={
'config.yaml': {'location': {'repositories': [{'path': 'foo/bar', 'label': 'repo'}]}}
},
)
def test_guard_configuration_contains_repository_does_not_raise_when_repository_not_given(): def test_guard_configuration_contains_repository_does_not_raise_when_repository_not_given():
module.guard_configuration_contains_repository( module.guard_configuration_contains_repository(
repository=None, configurations={'config.yaml': {'location': {'repositories': ['repo']}}} repository=None, configurations={'config.yaml': {'location': {'repositories': ['repo']}}}