Add unit tests for osm_config
[osm/LCM.git] / osm_lcm / tests / test_osm_config.py
1 # Copyright 2022 Canonical Ltd.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from unittest import TestCase
16 from osm_lcm.osm_config import OsmConfigBuilder
17
18
19 class TestOsmConfig(TestCase):
20 def test_k8s_services(self):
21 input_services = {
22 "services": [
23 {
24 "name": "ldap",
25 "type": "LoadBalancer",
26 "external_ip": ["1.1.1.1"],
27 "ports": [{"name": "ldap", "port": 1234, "protocol": "TCP"}],
28 },
29 {
30 "name": "ldap-internal",
31 "type": "ClusterIP",
32 "cluster_ip": "10.10.10.10",
33 "ports": [
34 {"name": "ldap-internal", "port": 1234, "protocol": "TCP"}
35 ],
36 },
37 ]
38 }
39 expected_services = {
40 "ldap": {
41 "type": "LoadBalancer",
42 "ip": ["1.1.1.1"],
43 "ports": {"ldap": {"port": 1234, "protocol": "TCP"}},
44 },
45 "ldap-internal": {
46 "type": "ClusterIP",
47 "ip": ["10.10.10.10"],
48 "ports": {"ldap-internal": {"port": 1234, "protocol": "TCP"}},
49 },
50 }
51 self.assertEqual(
52 OsmConfigBuilder(k8s=input_services).build(),
53 {"v0": {"k8s": {"services": expected_services}}},
54 )