diff --git a/CHANGELOG.md b/CHANGELOG.md index 843c5cd..43d6059 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ The project doesn't use version numbers. Each entry is one merge into `master`, Nothing yet. +## 2026-11-11 · [#6](https://github.com/tronyx/HealthChecks-Linux/pull/6) + +### Fixed + +- `--migrate` puts a blank line before the first `[[check]]` table in the file that it writes. Before, that table came right after the last line of `[hosts]` or of an `[auth.]` table. The file worked the same, but it was harder to read. + ## 2026-11-10 · [#5](https://github.com/tronyx/HealthChecks-Linux/pull/5) HealthChecks Linux is rewritten in Python. The checks are mostly the same, but you must move your settings to a new configuration file. Read the lines marked **Breaking** before you update. diff --git a/healthchecks_linux.py b/healthchecks_linux.py index 6e6b64d..c0c3d68 100755 --- a/healthchecks_linux.py +++ b/healthchecks_linux.py @@ -47,7 +47,7 @@ print(f"healthchecks-linux: Python 3.10 or newer is needed, but this is Python {_version}", file=sys.stderr) sys.exit(2) -__version__ = "2026-11-10" +__version__ = "2026-11-11" EXIT_OK = 0 EXIT_ERROR = 1 @@ -1132,7 +1132,7 @@ def render_migration(migration: Migration, source: Path) -> str: f"password = {_toml(credentials.password)}", "", ] - return "\n".join(lines) + "\n".join(migration.checks) + return "\n".join([*lines, *migration.checks]) def write_migrated_config(target: Path, text: str) -> None: diff --git a/tests/test_migrate.py b/tests/test_migrate.py index c5daf58..25e10d6 100644 --- a/tests/test_migrate.py +++ b/tests/test_migrate.py @@ -1,5 +1,6 @@ """Tests for --migrate: writing healthchecks.toml from a configured copy of the Bash script.""" +import itertools import stat from pathlib import Path @@ -186,6 +187,23 @@ def test_migrated_hosts(migrated: tuple[Path, str]) -> None: assert '[hosts]\ndomain = "example.test"\ndocker = "10.0.0.5"\nunifi_nvr = "10.0.0.6"\nempty = ""\n' in text +@pytest.mark.parametrize( + ("text", "has_auth"), + [(CONFIGURED, True), (CONFIGURED.replace(" check_nagios\n", ""), False)], + ids=["checks after the auth tables", "checks after the hosts"], +) +def test_migrated_tables_follow_a_blank_line(tmp_path: Path, text: str, has_auth: bool) -> None: + script = tmp_path / "application_healthchecks_generic.sh" + script.write_text(text, encoding="utf-8") + target = tmp_path / "healthchecks.toml" + assert main(["--migrate", str(script), "-c", str(target)], {}) == 0 + migrated = target.read_text(encoding="utf-8") + assert ("\n[auth." in migrated) is has_auth + lines = migrated.split("\n") + assert [line for before, line in itertools.pairwise(lines) if line.startswith("[") and before] == [] + assert migrated.endswith("]\n") + + def test_migration_report(migrated: tuple[Path, str]) -> None: out = migrated[1] for line in (