diff --git a/tests/test_inventory.py b/tests/test_inventory.py index c8216a0d1..45f9fdf6a 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -7,12 +7,23 @@ "inventory tests" +import argparse +import importlib import unittest +from kapitan import cached from kapitan.resources import inventory class InventoryTargetTest(unittest.TestCase): + def setUp(self): + # Setup `cached.args` if it's not setup yet + cached.args.setdefault("compile", argparse.Namespace()) + # Configure `compile.inventory_path` and `inventory-backend`. This + # allows us to reuse the tests by inheriting from this test class. + cached.args["compile"].inventory_path = "inventory" + cached.args["inventory-backend"] = "reclass" + def test_inventory_target(self): inv = inventory(["examples/kubernetes"], "minikube-es") self.assertEqual(inv["parameters"]["cluster"]["name"], "minikube") @@ -20,3 +31,12 @@ def test_inventory_target(self): def test_inventory_all_targets(self): inv = inventory(["examples/kubernetes"], None) self.assertNotEqual(inv.get("minikube-es"), None) + + +class InventoryTargetTestReclassRs(InventoryTargetTest): + def setUp(self): + if not importlib.util.find_spec("reclass_rs"): + self.skipTest("reclass-rs not available") + + super().setUp() + cached.args["inventory-backend"] = "reclass-rs" diff --git a/tests/test_remote_inventory.py b/tests/test_remote_inventory.py index 923235d58..863e9b343 100644 --- a/tests/test_remote_inventory.py +++ b/tests/test_remote_inventory.py @@ -1,3 +1,4 @@ +import argparse import os import sys import unittest @@ -17,7 +18,7 @@ ) -class RemoteInventoryTest(unittest.TestCase): +class RemoteInventoryTestFetch(unittest.TestCase): def setUp(self): os.chdir( os.path.join( @@ -89,6 +90,17 @@ def test_unpack_http_inv(self): rmtree(temp_dir) rmtree(output_dir) + +class RemoteInventoryTest(unittest.TestCase): + extraArgv = [] + + def setUp(self): + os.chdir( + os.path.join( + os.path.abspath(os.path.dirname(__file__)), "test_remote_inventory", "environment_one" + ) + ) + def test_compile_fetch(self): """Run $ kapitan compile --force-fetch --output-path=some/dir/ --inventory-path=another/dir --targets remoteinv-example remoteinv-nginx zippedinv were some/dir/ & another/dir/ are directories chosen by the user @@ -119,7 +131,7 @@ def test_compile_fetch(self): "remoteinv-example", "remoteinv-nginx", "zippedinv", - ] + ] + self.extraArgv main() self.assertTrue(os.path.isfile(os.path.join(temp_inv, "targets", "remoteinv-nginx.yml"))) @@ -152,7 +164,7 @@ def test_compile_fetch_classes_that_doesnot_exist_yet(self): os.path.join(temp_dir, "inventory"), "-t", "nginx", - ] + ] + self.extraArgv main() self.assertTrue(os.path.exists(os.path.join(temp_dir, "compiled", "nginx"))) rmtree(temp_dir) @@ -186,7 +198,7 @@ def test_force_fetch(self): temp_inv, "--targets", "remoteinv-example", - ] + ] + self.extraArgv main() fname = os.path.join(temp_inv, "targets", "zippedinv.yml") @@ -212,7 +224,7 @@ def test_force_fetch(self): temp_inv, "--targets", "remoteinv-example", - ] + ] + self.extraArgv main() # zippedinv.yml overwritten force_fetched_data = json.loads(yaml_load([os.path.dirname(fname)], os.path.basename(fname))) @@ -224,3 +236,16 @@ def test_force_fetch(self): def tearDown(self): os.chdir("../../../") reset_cache() + + +class RemoteInventoryTestReclassRs(RemoteInventoryTest): + def setUp(self): + super().setUp() + self.extraArgv = ["--inventory-backend=reclass-rs"] + + @unittest.skip( + "Broken with reclass-rs due to duplicate key in class `component.mysql` " + + "(`parameters.mysql.storage` is duplicated)" + ) + def test_compile_fetch(self): + pass