feat(slice-6): implement config loader, CLI check mode, comprehensive documentation, and shell completions
This commit is contained in:
1 parent
869fd241e7
commit
e5784db650
9 files changed
+616
-29
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import json
|
||||
import sys
|
||||
import unittest
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from inventory_collector.cli import main
|
||||
|
||||
class TestCliIntegration(unittest.TestCase):
|
||||
def test_cli_dry_run_inspection(self):
|
||||
stdout_capture = StringIO()
|
||||
stderr_capture = StringIO()
|
||||
old_stdout, old_stderr = sys.stdout, sys.stderr
|
||||
try:
|
||||
sys.stdout = stdout_capture
|
||||
sys.stderr = stderr_capture
|
||||
code = main(["--check"])
|
||||
self.assertEqual(code, 0)
|
||||
out = stdout_capture.getvalue()
|
||||
self.assertIn("NAME", out)
|
||||
self.assertIn("IP ADDRESS", out)
|
||||
self.assertIn("k3s-master-0", out)
|
||||
finally:
|
||||
sys.stdout = old_stdout
|
||||
sys.stderr = old_stderr
|
||||
|
||||
def test_cli_dynamic_json_list(self):
|
||||
stdout_capture = StringIO()
|
||||
stderr_capture = StringIO()
|
||||
old_stdout, old_stderr = sys.stdout, sys.stderr
|
||||
try:
|
||||
sys.stdout = stdout_capture
|
||||
sys.stderr = stderr_capture
|
||||
code = main(["--list"])
|
||||
self.assertEqual(code, 0)
|
||||
parsed = json.loads(stdout_capture.getvalue())
|
||||
self.assertIn("_meta", parsed)
|
||||
self.assertIn("hostvars", parsed["_meta"])
|
||||
finally:
|
||||
sys.stdout = old_stdout
|
||||
sys.stderr = old_stderr
|
||||
|
||||
def test_cli_file_output_auto_xml(self):
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
target_xml = Path(tmpdir) / "output.xml"
|
||||
code = main(["-o", str(target_xml)])
|
||||
self.assertEqual(code, 0)
|
||||
self.assertTrue(target_xml.exists())
|
||||
content = target_xml.read_text(encoding="utf-8")
|
||||
self.assertIn("<inventory", content)
|
||||
self.assertIn("<host name=", content)
|
||||
|
||||
def test_cli_file_output_auto_ini(self):
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
target_ini = Path(tmpdir) / "hosts.ini"
|
||||
code = main(["-o", str(target_ini)])
|
||||
self.assertEqual(code, 0)
|
||||
self.assertTrue(target_ini.exists())
|
||||
content = target_ini.read_text(encoding="utf-8")
|
||||
self.assertIn("ansible_host=", content)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user