test: add unit tests for core, parser and operations
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from sshctl.export.inventory import _to_group_name, generate_inventory
|
||||
|
||||
|
||||
def test_to_group_name_simple() -> None:
|
||||
assert _to_group_name("internal") == "internal"
|
||||
assert _to_group_name("cluster1") == "cluster1"
|
||||
|
||||
|
||||
def test_to_group_name_with_hyphens() -> None:
|
||||
assert _to_group_name("8xx-serverfarm") == "z8xx_serverfarm"
|
||||
|
||||
|
||||
def test_to_group_name_starts_with_digit() -> None:
|
||||
assert _to_group_name("8xx") == "z8xx"
|
||||
|
||||
|
||||
def test_generate_inventory_no_ssh_dir(tmp_path: Path) -> None:
|
||||
result = generate_inventory(tmp_path / "nonexistent")
|
||||
assert result == {}
|
||||
|
||||
|
||||
def test_generate_inventory_empty_config(tmp_path: Path) -> None:
|
||||
ssh_dir = tmp_path / ".ssh"
|
||||
ssh_dir.mkdir()
|
||||
(ssh_dir / "config").write_text("Host *\n User root\n")
|
||||
result = generate_inventory(ssh_dir)
|
||||
assert result == {}
|
||||
Reference in New Issue
Block a user