From 025f00f9242c5009c713e179018b8d3f1e6d9fac Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 5 Jan 2026 21:25:46 +1100 Subject: [PATCH] Fix tests --- CHANGELOG.md | 2 +- pyproject.toml | 2 +- tests/test_validate.py | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60aad11..dca9314 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/pyproject.toml b/pyproject.toml index 9835ace..9170b27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "enroll" -version = "0.3.1" +version = "0.4.0" description = "Enroll a server's running state retrospectively into Ansible" authors = ["Miguel Jacq "] license = "GPL-3.0-or-later" diff --git a/tests/test_validate.py b/tests/test_validate.py index 4f7977e..1a10569 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -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) -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["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)]) with pytest.raises(SystemExit) as e: 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