2
0
Эх сурвалжийг харах

add tests for repo labels

Divyansh Singh 2 жил өмнө
parent
commit
b336b9bedf

+ 27 - 0
tests/unit/config/test_normalize.py

@@ -92,6 +92,21 @@ from borgmatic.config import normalize as module
             {'location': {'repositories': [{'path': '/repo'}]}},
             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(
@@ -105,3 +120,15 @@ def test_normalize_applies_hard_coded_normalization_to_config(
         assert logs
     else:
         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']
+                }
+            },
+        )

+ 10 - 0
tests/unit/config/test_validate.py

@@ -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():
     module.guard_configuration_contains_repository(
         repository=None, configurations={'config.yaml': {'location': {'repositories': ['repo']}}}