|
| 1 | +# SPDX-License-Identifier: GPL-2.0 |
| 2 | + |
| 3 | +import json |
| 4 | +import os |
| 5 | +import unittest |
| 6 | + |
| 7 | +from tests.integration.test_utils import RunSubprocessMixin |
| 8 | +from tests.integration.test_utils import podman_compose_path |
| 9 | +from tests.integration.test_utils import test_path |
| 10 | + |
| 11 | + |
| 12 | +def compose_yaml_path() -> str: |
| 13 | + return os.path.join(os.path.join(test_path(), "healthcheck"), "docker-compose.yml") |
| 14 | + |
| 15 | + |
| 16 | +class TestHealthecheck(unittest.TestCase, RunSubprocessMixin): |
| 17 | + def test_healthcheck(self) -> None: |
| 18 | + up_cmd = [ |
| 19 | + "coverage", |
| 20 | + "run", |
| 21 | + podman_compose_path(), |
| 22 | + "-f", |
| 23 | + os.path.join(test_path(), "healthcheck", "docker-compose.yml"), |
| 24 | + "up", |
| 25 | + "-d", |
| 26 | + ] |
| 27 | + self.run_subprocess_assert_returncode(up_cmd) |
| 28 | + |
| 29 | + command_container_id = [ |
| 30 | + "podman", |
| 31 | + "ps", |
| 32 | + "-a", |
| 33 | + "--filter", |
| 34 | + "label=io.podman.compose.project=healthcheck", |
| 35 | + "--format", |
| 36 | + '"{{.ID}}"', |
| 37 | + ] |
| 38 | + out, _ = self.run_subprocess_assert_returncode(command_container_id) |
| 39 | + self.assertNotEqual(out, b"") |
| 40 | + container_id = out.decode("utf-8").strip().replace('"', "") |
| 41 | + |
| 42 | + command_inspect = ["podman", "container", "inspect", container_id] |
| 43 | + |
| 44 | + out, _ = self.run_subprocess_assert_returncode(command_inspect) |
| 45 | + out_string = out.decode("utf-8") |
| 46 | + inspect = json.loads(out_string) |
| 47 | + healthcheck_obj = inspect[0]["Config"]["Healthcheck"] |
| 48 | + expected = { |
| 49 | + "Test": ["CMD-SHELL", "curl -f http://localhost || exit 1"], |
| 50 | + "StartPeriod": 10000000000, |
| 51 | + "Interval": 60000000000, |
| 52 | + "Timeout": 10000000000, |
| 53 | + "Retries": 3, |
| 54 | + } |
| 55 | + self.assertEqual(healthcheck_obj, expected) |
| 56 | + |
| 57 | + # StartInterval is not available in the config object |
| 58 | + create_obj = inspect[0]["Config"]["CreateCommand"] |
| 59 | + self.assertIn("--health-startup-interval", create_obj) |
0 commit comments