Files
computer-playbook/tests/unit/utils/docker/test_version_updater.py
T
Environment TestandClaude Sonnet 4.6 bf8c535988 feat(update): add docker image version updater CLI, workflow, and lint tests
- Add utils/docker/version_updater.py with CLI for updating Docker image versions
- Add cli/fix/docker_image_versions module wrapping the updater
- Add .github/workflows/update.yml replacing update-skills.yml
- Add scripts/github/ helpers: check_git_changes, install_update_python, open_update_pr, update_docker_image_versions
- Add tests/lint/filesystem/ for scripts/ and utils/ folder file-type enforcement
- Add tests/lint/ansible/ for legacy module usage and vars usage checks
- Reorganize tests/lint/repository/ and move test_vars_usage_in_yaml.py to ansible/
- Add artefact docs: files/github/workflow.md, scripst.md, utils.md
- Apply documentation.md standards to all modified markdown files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 18:38:39 +02:00

46 lines
1.4 KiB
Python

from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from utils.docker.version_updater import (
latest_semver,
update_config_versions,
)
class TestDockerVersionUpdater(unittest.TestCase):
def test_latest_semver_respects_depth(self) -> None:
tags = ["4", "4.5", "4.6", "4.5.1", "5"]
self.assertEqual(latest_semver(tags, 1), "5")
self.assertEqual(latest_semver(tags, 2), "4.6")
self.assertEqual(latest_semver(tags, 3), "4.5.1")
def test_update_config_versions_updates_only_target_services(self) -> None:
original = """compose:
services:
moodle:
version: "4.5" # Keep comment
image: bitnamilegacy/moodle
nginx:
version: alpine
image: nginx
"""
with tempfile.TemporaryDirectory() as tmpdir:
config_path = Path(tmpdir) / "main.yml"
config_path.write_text(original, encoding="utf-8")
changed = update_config_versions(config_path, {"moodle": "5.0"})
self.assertTrue(changed)
updated = config_path.read_text(encoding="utf-8")
self.assertIn('version: "5.0" # Keep comment', updated)
self.assertIn("version: alpine", updated)
self.assertNotIn('version: "4.5" # Keep comment', updated)
if __name__ == "__main__":
unittest.main()