diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..7c7605d --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +# pytest package marker diff --git a/tests/test_inventory.py b/tests/test_inventory.py new file mode 100644 index 0000000..7eb771a --- /dev/null +++ b/tests/test_inventory.py @@ -0,0 +1,46 @@ +import json +import tempfile +from pathlib import Path + +import pytest + +from metis.pkg import inventory + +def test_load_and_find_node(): + data = { + "classes": [ + { + "name": "rpi5", + "arch": "arm64", + "os": "ubuntu", + "image": "file:///tmp/base.img", + "checksum": "sha256:deadbeef", + "default_labels": {"hardware": "rpi5"}, + } + ], + "nodes": [ + { + "name": "titan-04", + "class": "rpi5", + "hostname": "titan-04", + "ip": "192.168.22.30", + "k3s_role": "agent", + } + ], + } + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / "inv.yaml" + path.write_text(json.dumps(data)) + inv = inventory.Load(path) + node, cls, err = inv.FindNode("titan-04") + assert err is None + assert node.Hostname == "titan-04" + assert cls.Arch == "arm64" + + +def test_find_node_missing(): + inv = inventory.Inventory(classes=[], nodes=[]) + node, cls, err = inv.FindNode("missing") + assert err is not None + assert node is None + assert cls is None