|
| 1 | +import os.path |
| 2 | +from unittest import TestCase |
| 3 | +from unittest.mock import MagicMock, patch |
| 4 | +import yaml |
| 5 | + |
| 6 | +from _modules import metalk8s_olm |
| 7 | + |
| 8 | +from tests.unit import mixins |
| 9 | +from tests.unit import utils |
| 10 | + |
| 11 | +YAML_TESTS_FILE = os.path.join( |
| 12 | + os.path.dirname(os.path.abspath(__file__)), "files", "test_metalk8s_olm.yaml" |
| 13 | +) |
| 14 | + |
| 15 | +with open(YAML_TESTS_FILE) as fd: |
| 16 | + YAML_TESTS_CASES = yaml.safe_load(fd) |
| 17 | + |
| 18 | + |
| 19 | +class Metalk8sOLMTestCase(TestCase, mixins.LoaderModuleMockMixin): |
| 20 | + """Test case for the olm module""" |
| 21 | + |
| 22 | + loader_module = metalk8s_olm |
| 23 | + |
| 24 | + def test_virtual(self): |
| 25 | + """ |
| 26 | + Tests the return of `__virtual__` function |
| 27 | + """ |
| 28 | + self.assertEqual(metalk8s_olm.__virtual__(), "metalk8s_olm") |
| 29 | + |
| 30 | + @utils.parameterized_from_cases(YAML_TESTS_CASES["clustercatalog_serving"]) |
| 31 | + def test_check_clustercatalog_serving(self, name, manifest, expected_result): |
| 32 | + """ |
| 33 | + Tests the `check_clustercatalog_serving` function |
| 34 | + """ |
| 35 | + get_object_mock = MagicMock(return_value=manifest) |
| 36 | + with patch.dict( |
| 37 | + metalk8s_olm.__salt__, {"metalk8s_kubernetes.get_object": get_object_mock} |
| 38 | + ): |
| 39 | + self.assertEqual( |
| 40 | + metalk8s_olm.check_clustercatalog_serving(name), expected_result |
| 41 | + ) |
| 42 | + |
| 43 | + @utils.parameterized_from_cases(YAML_TESTS_CASES["clusterextension_installed"]) |
| 44 | + def test_check_clusterextension_installed(self, name, manifest, expected_result): |
| 45 | + """ |
| 46 | + Tests the `check_clusterextension_installed` function |
| 47 | + """ |
| 48 | + get_object_mock = MagicMock(return_value=manifest) |
| 49 | + with patch.dict( |
| 50 | + metalk8s_olm.__salt__, {"metalk8s_kubernetes.get_object": get_object_mock} |
| 51 | + ): |
| 52 | + self.assertEqual( |
| 53 | + metalk8s_olm.check_clusterextension_installed(name), expected_result |
| 54 | + ) |
0 commit comments