Add unit tests for osm_config 19/12019/2
authorDavid Garcia <david.garcia@canonical.com>
Mon, 9 May 2022 14:18:27 +0000 (16:18 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 18 May 2022 08:44:51 +0000 (10:44 +0200)
Change-Id: Ica9caf96191808dd27036dbd9b14ff0837d5393c
Signed-off-by: David Garcia <david.garcia@canonical.com>
osm_lcm/tests/test_osm_config.py [new file with mode: 0644]

diff --git a/osm_lcm/tests/test_osm_config.py b/osm_lcm/tests/test_osm_config.py
new file mode 100644 (file)
index 0000000..c129e24
--- /dev/null
@@ -0,0 +1,54 @@
+# Copyright 2022 Canonical Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+#     Unless required by applicable law or agreed to in writing, software
+#     distributed under the License is distributed on an "AS IS" BASIS,
+#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#     See the License for the specific language governing permissions and
+#     limitations under the License.
+
+from unittest import TestCase
+from osm_lcm.osm_config import OsmConfigBuilder
+
+
+class TestOsmConfig(TestCase):
+    def test_k8s_services(self):
+        input_services = {
+            "services": [
+                {
+                    "name": "ldap",
+                    "type": "LoadBalancer",
+                    "external_ip": ["1.1.1.1"],
+                    "ports": [{"name": "ldap", "port": 1234, "protocol": "TCP"}],
+                },
+                {
+                    "name": "ldap-internal",
+                    "type": "ClusterIP",
+                    "cluster_ip": "10.10.10.10",
+                    "ports": [
+                        {"name": "ldap-internal", "port": 1234, "protocol": "TCP"}
+                    ],
+                },
+            ]
+        }
+        expected_services = {
+            "ldap": {
+                "type": "LoadBalancer",
+                "ip": ["1.1.1.1"],
+                "ports": {"ldap": {"port": 1234, "protocol": "TCP"}},
+            },
+            "ldap-internal": {
+                "type": "ClusterIP",
+                "ip": ["10.10.10.10"],
+                "ports": {"ldap-internal": {"port": 1234, "protocol": "TCP"}},
+            },
+        }
+        self.assertEqual(
+            OsmConfigBuilder(k8s=input_services).build(),
+            {"v0": {"k8s": {"services": expected_services}}},
+        )