test: add inventory unit tests
This commit is contained in:
parent
f08546ebd1
commit
f22f8cfe30
1
tests/__init__.py
Normal file
1
tests/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# pytest package marker
|
||||
46
tests/test_inventory.py
Normal file
46
tests/test_inventory.py
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user