feat(slice-1): implement tracer bullet pipeline with PyYAML check and pure-python fallback

This commit is contained in:
soda64 committed 2026-10-03 08:29:59 +02:00
1 parent 937acc2548
commit 68802710b0
12 files changed
+331 -1

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
import unittest
import sys
from io import StringIO
from inventory_collector.models import HostRecord, InventoryData
from inventory_collector.exporters.ansible_yaml import AnsibleYamlExporter
from inventory_collector.cli import main
class TestTracerBullet(unittest.TestCase):
def test_host_record_creation(self):
host = HostRecord(
name="k3s-master-0",
ansible_host="192.168.5.70",
ansible_user="lain",
groups=["k3s_master", "k3s_cluster"],
tags=["control-plane", "proxmox"],
source="test"
)
self.assertEqual(host.name, "k3s-master-0")
self.assertEqual(host.ansible_host, "192.168.5.70")
self.assertEqual(host.ansible_user, "lain")
self.assertIn("k3s_master", host.groups)
def test_ansible_yaml_exporter_output(self):
inv = InventoryData()
host = HostRecord(
name="k3s-master-0",
ansible_host="192.168.5.70",
ansible_user="lain",
groups=["k3s_master"],
tags=["control-plane"]
)
inv.add_host(host)
exporter = AnsibleYamlExporter()
output = exporter.export(inv)
self.assertIn("all:", output)
self.assertIn("children:", output)
self.assertIn("k3s_master:", output)
self.assertIn("k3s-master-0:", output)
self.assertIn("192.168.5.70", output)
def test_cli_runs_tracer(self):
stdout_capture = StringIO()
stderr_capture = StringIO()
old_stdout, old_stderr = sys.stdout, sys.stderr
try:
sys.stdout = stdout_capture
sys.stderr = stderr_capture
exit_code = main(["--dry-run"])
self.assertEqual(exit_code, 0)
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
if __name__ == "__main__":
unittest.main()