DEVX-14: feat: fix molecule platforms to use sleep infinity, add --platforms-file
This commit is contained in:
@@ -163,10 +163,7 @@ class TestCli:
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--list-platforms"])
|
||||
assert result.exit_code == 0
|
||||
assert "ubuntu-2204" in result.output
|
||||
assert "ubuntu-2404" in result.output
|
||||
assert "debian-12" in result.output
|
||||
assert "archlinux" in result.output
|
||||
assert "ubuntu-2604" in result.output
|
||||
|
||||
def test_no_runner_index_prints_all_groups(self, tmp_path: Path) -> None:
|
||||
from click.testing import CliRunner
|
||||
@@ -198,7 +195,7 @@ class TestCli:
|
||||
assert result.exit_code == 0
|
||||
# Output should contain encoded pairs with platform info
|
||||
assert "alpha|" in result.output
|
||||
assert "ubuntu-2204" in result.output
|
||||
assert "ubuntu-2604" in result.output
|
||||
|
||||
|
||||
class TestGithubEnv:
|
||||
@@ -409,7 +406,7 @@ class TestCliMultiRole:
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--roles-root", str(roles), "--list-platforms"])
|
||||
assert result.exit_code == 0
|
||||
assert "ubuntu-2204" in result.output
|
||||
assert "ubuntu-2604" in result.output
|
||||
|
||||
def test_roles_root_no_runner_index_prints_groups(self, tmp_path: Path) -> None:
|
||||
"""--roles-root without --runner-index prints all groups."""
|
||||
@@ -422,6 +419,27 @@ class TestCliMultiRole:
|
||||
assert "Runner 0:" in result.output
|
||||
assert "Runner 1:" in result.output
|
||||
|
||||
def test_platforms_file_overrides_default(self, tmp_path: Path) -> None:
|
||||
"""--platforms-file loads custom platforms from JSON."""
|
||||
import json
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from devx.molecule.distribute_molecule import cli
|
||||
|
||||
roles = tmp_path / "roles"
|
||||
(roles / "role-a" / "molecule" / "default").mkdir(parents=True)
|
||||
platforms_file = tmp_path / "platforms.json"
|
||||
custom = [{"name": "custom-os", "image": "custom:latest", "command": "sleep infinity"}]
|
||||
platforms_file.write_text(json.dumps(custom))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
cli, ["--roles-root", str(roles), "--platforms-file", str(platforms_file), "--list-platforms"]
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert "custom-os" in result.output
|
||||
assert "custom:latest" in result.output
|
||||
|
||||
def test_roles_root_skips_non_dir_role(self, tmp_path: Path) -> None:
|
||||
"""Non-directory entries in roles root are skipped."""
|
||||
roles = tmp_path / "roles"
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
"""Unit tests for scripts/ci/platforms.py."""
|
||||
"""Unit tests for devx.molecule.platforms."""
|
||||
|
||||
from devx.molecule.platforms import PLATFORMS
|
||||
import json
|
||||
|
||||
from devx.molecule.platforms import PLATFORMS, load_platforms
|
||||
|
||||
|
||||
class TestPlatforms:
|
||||
def test_platforms_not_empty(self) -> None:
|
||||
assert len(PLATFORMS) >= 4
|
||||
assert len(PLATFORMS) >= 1
|
||||
|
||||
def test_each_platform_has_required_keys(self) -> None:
|
||||
for p in PLATFORMS:
|
||||
@@ -17,9 +19,40 @@ class TestPlatforms:
|
||||
names = [p["name"] for p in PLATFORMS]
|
||||
assert len(names) == len(set(names))
|
||||
|
||||
def test_platforms_use_sleep_infinity(self) -> None:
|
||||
"""All default platforms must use sleep infinity, not systemd."""
|
||||
for p in PLATFORMS:
|
||||
assert p["command"] == "sleep infinity", f"Platform {p['name']} uses {p['command']}"
|
||||
|
||||
def test_known_platforms_present(self) -> None:
|
||||
names = {p["name"] for p in PLATFORMS}
|
||||
assert "ubuntu-2204" in names
|
||||
assert "ubuntu-2404" in names
|
||||
assert "debian-12" in names
|
||||
assert "archlinux" in names
|
||||
assert "ubuntu-2604" in names
|
||||
|
||||
|
||||
class TestLoadPlatforms:
|
||||
def test_load_platforms_default(self, tmp_path) -> None: # type: ignore[no-untyped-def]
|
||||
"""load_platforms with no file returns PLATFORMS."""
|
||||
result = load_platforms(None)
|
||||
assert result == PLATFORMS
|
||||
|
||||
def test_load_platforms_from_file(self, tmp_path) -> None: # type: ignore[no-untyped-def]
|
||||
"""load_platforms reads custom platforms from JSON file."""
|
||||
custom = [
|
||||
{"name": "custom-os", "image": "custom:latest", "command": "sleep infinity"},
|
||||
]
|
||||
f = tmp_path / "platforms.json"
|
||||
f.write_text(json.dumps(custom))
|
||||
result = load_platforms(f)
|
||||
assert result == custom
|
||||
|
||||
def test_load_platforms_missing_file_falls_back(self, tmp_path) -> None: # type: ignore[no-untyped-def]
|
||||
"""load_platforms falls back to PLATFORMS when file doesn't exist."""
|
||||
result = load_platforms(tmp_path / "nonexistent.json")
|
||||
assert result == PLATFORMS
|
||||
|
||||
def test_load_platforms_empty_list_falls_back(self, tmp_path) -> None: # type: ignore[no-untyped-def]
|
||||
"""load_platforms falls back to PLATFORMS when file has empty list."""
|
||||
f = tmp_path / "platforms.json"
|
||||
f.write_text("[]")
|
||||
result = load_platforms(f)
|
||||
assert result == PLATFORMS
|
||||
|
||||
Reference in New Issue
Block a user