bd31a3f2f3
- pyproject.toml (hatchling) with ruff/mypy/pytest dev deps - src/ci_orchestrator/: config, credentials, backends (Protocol + WorkstationVmrunBackend), transport (WinRM via pypsrp, SSH via paramiko) - CLI entry point with PoC 'wait-ready' subcommand (Windows + Linux guests) - tests/python/: 35 unit tests, 83% coverage, all backends/transport mocked - gitea/workflows/lint.yml: new 'python' job (ruff + mypy --strict + pytest --cov-fail-under=70) - config.example.toml + README setup section + .gitignore Python entries Neutral VmBackend Protocol prepared for Phase C ESXi extension. See plans/implementation-plan-A-B.md step A1.
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
"""Tests for ci_orchestrator.config."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from ci_orchestrator.config import load_config
|
|
|
|
|
|
def test_defaults_are_os_aware() -> None:
|
|
cfg = load_config(env={})
|
|
if os.name == "nt":
|
|
assert str(cfg.paths.root) == r"F:\CI"
|
|
else:
|
|
assert str(cfg.paths.root) == "/var/lib/ci"
|
|
|
|
|
|
def test_env_overrides_paths(tmp_path: Path) -> None:
|
|
cfg = load_config(
|
|
env={
|
|
"CI_ROOT": str(tmp_path / "root"),
|
|
"CI_TEMPLATES": str(tmp_path / "tpl"),
|
|
"CI_BUILD_VMS": str(tmp_path / "bvm"),
|
|
"CI_ARTIFACTS": str(tmp_path / "art"),
|
|
"CI_KEYS": str(tmp_path / "keys"),
|
|
}
|
|
)
|
|
assert cfg.paths.root == tmp_path / "root"
|
|
assert cfg.paths.templates == tmp_path / "tpl"
|
|
assert cfg.paths.build_vms == tmp_path / "bvm"
|
|
assert cfg.paths.artifacts == tmp_path / "art"
|
|
assert cfg.paths.keys == tmp_path / "keys"
|
|
|
|
|
|
def test_toml_overrides_defaults(tmp_path: Path) -> None:
|
|
toml = tmp_path / "config.toml"
|
|
toml.write_text(
|
|
'[paths]\n'
|
|
f'root = "{(tmp_path / "altroot").as_posix()}"\n'
|
|
'[backend]\n'
|
|
'type = "workstation"\n'
|
|
'extra = "value"\n',
|
|
encoding="utf-8",
|
|
)
|
|
cfg = load_config(config_path=toml, env={})
|
|
assert cfg.paths.root == tmp_path / "altroot"
|
|
assert cfg.backend.type == "workstation"
|
|
assert cfg.backend.options == {"extra": "value"}
|
|
|
|
|
|
def test_env_wins_over_toml(tmp_path: Path) -> None:
|
|
toml = tmp_path / "config.toml"
|
|
toml.write_text(
|
|
f'[paths]\nroot = "{(tmp_path / "fromtoml").as_posix()}"\n',
|
|
encoding="utf-8",
|
|
)
|
|
cfg = load_config(
|
|
config_path=toml,
|
|
env={"CI_ROOT": str(tmp_path / "fromenv")},
|
|
)
|
|
assert cfg.paths.root == tmp_path / "fromenv"
|