Fix tests
Some checks failed
Lint / test (push) Waiting to run
Trivy / test (push) Waiting to run
CI / test (push) Has been cancelled

This commit is contained in:
Miguel Jacq 2026-01-05 21:25:46 +11:00
parent 66d032d981
commit 025f00f924
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
3 changed files with 35 additions and 4 deletions

View file

@ -1,4 +1,4 @@
# 0.4.0 # 0.4.0 (not yet released)
* Introduce `enroll validate` - a tool to validate a harvest against the state schema, or check for missing or orphaned obsolete artifacts in a harvest. * Introduce `enroll validate` - a tool to validate a harvest against the state schema, or check for missing or orphaned obsolete artifacts in a harvest.

View file

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "enroll" name = "enroll"
version = "0.3.1" version = "0.4.0"
description = "Enroll a server's running state retrospectively into Ansible" description = "Enroll a server's running state retrospectively into Ansible"
authors = ["Miguel Jacq <mig@mig5.net>"] authors = ["Miguel Jacq <mig@mig5.net>"]
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"

View file

@ -131,7 +131,7 @@ def test_validate_schema_error_is_reported(tmp_path: Path):
assert any(e.startswith("schema /host/os") for e in res.errors) assert any(e.startswith("schema /host/os") for e in res.errors)
def test_cli_validate_exits_2_on_validation_error(monkeypatch, tmp_path: Path): def test_cli_validate_exits_1_on_validation_error(monkeypatch, tmp_path: Path):
state = _base_state() state = _base_state()
state["roles"]["etc_custom"]["managed_files"].append( state["roles"]["etc_custom"]["managed_files"].append(
{ {
@ -148,4 +148,35 @@ def test_cli_validate_exits_2_on_validation_error(monkeypatch, tmp_path: Path):
monkeypatch.setattr(sys, "argv", ["enroll", "validate", str(bundle)]) monkeypatch.setattr(sys, "argv", ["enroll", "validate", str(bundle)])
with pytest.raises(SystemExit) as e: with pytest.raises(SystemExit) as e:
cli.main() cli.main()
assert e.value.code == 2 assert e.value.code == 1
def test_cli_validate_exits_1_on_validation_warning_with_flag(
monkeypatch, tmp_path: Path
):
state = _base_state()
state["roles"]["etc_custom"]["managed_files"].append(
{
"path": "/etc/hosts",
"src_rel": "etc/hosts",
"owner": "root",
"group": "root",
"mode": "0644",
"reason": "custom_specific_path",
}
)
bundle = _write_bundle(tmp_path, state)
art = bundle / "artifacts" / "etc_custom" / "etc" / "hosts"
art.parent.mkdir(parents=True, exist_ok=True)
art.write_text("127.0.0.1 localhost\n", encoding="utf-8")
art2 = bundle / "artifacts" / "etc_custom" / "etc" / "hosts2"
art2.write_text("hello\n", encoding="utf-8")
monkeypatch.setattr(
sys, "argv", ["enroll", "validate", str(bundle), "--fail-on-warnings"]
)
with pytest.raises(SystemExit) as e:
cli.main()
assert e.value.code == 1