Skip to content

Commit

Permalink
Add test cases for inventory and remote inventory with reclass-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
simu committed Feb 26, 2024
1 parent 948ab2a commit fb39689
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
20 changes: 20 additions & 0 deletions tests/test_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,36 @@

"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")

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"
35 changes: 30 additions & 5 deletions tests/test_remote_inventory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import os
import sys
import unittest
Expand All @@ -17,7 +18,7 @@
)


class RemoteInventoryTest(unittest.TestCase):
class RemoteInventoryTestFetch(unittest.TestCase):
def setUp(self):
os.chdir(
os.path.join(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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)))
Expand All @@ -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

0 comments on commit fb39689

Please sign in to comment.