|
7 | 7 | """
|
8 | 8 |
|
9 | 9 | # pylint: disable=redefined-outer-name
|
| 10 | +import json |
10 | 11 | import os
|
11 | 12 | import unittest
|
12 | 13 |
|
@@ -89,3 +90,47 @@ def test_up(self, profiles, expected_services):
|
89 | 90 | actual_services[service] = service in actual_output
|
90 | 91 |
|
91 | 92 | self.assertEqual(expected_services, actual_services)
|
| 93 | + |
| 94 | + def test_healthcheck(self): |
| 95 | + up_cmd = [ |
| 96 | + "coverage", |
| 97 | + "run", |
| 98 | + podman_compose_path(), |
| 99 | + "-f", |
| 100 | + os.path.join(test_path(), "healthcheck", "docker-compose.yml"), |
| 101 | + "up", |
| 102 | + "-d", |
| 103 | + ] |
| 104 | + self.run_subprocess_assert_returncode(up_cmd) |
| 105 | + |
| 106 | + command_container_id = [ |
| 107 | + "podman", |
| 108 | + "ps", |
| 109 | + "-a", |
| 110 | + "--filter", |
| 111 | + "label=io.podman.compose.project=healthcheck", |
| 112 | + "--format", |
| 113 | + '"{{.ID}}"', |
| 114 | + ] |
| 115 | + out, _ = self.run_subprocess_assert_returncode(command_container_id) |
| 116 | + self.assertNotEqual(out, b"") |
| 117 | + container_id = out.decode("utf-8").strip().replace('"', "") |
| 118 | + |
| 119 | + command_inspect = ["podman", "container", "inspect", container_id] |
| 120 | + |
| 121 | + out, _ = self.run_subprocess_assert_returncode(command_inspect) |
| 122 | + out_string = out.decode("utf-8") |
| 123 | + inspect = json.loads(out_string) |
| 124 | + healthcheck_obj = inspect[0]["Config"]["Healthcheck"] |
| 125 | + expected = { |
| 126 | + "Test": ["CMD-SHELL", "/bin/sh -c 'curl -f http://localhost || exit 1'"], |
| 127 | + "StartPeriod": 10000000000, |
| 128 | + "Interval": 60000000000, |
| 129 | + "Timeout": 10000000000, |
| 130 | + "Retries": 3, |
| 131 | + } |
| 132 | + self.assertEqual(healthcheck_obj, expected) |
| 133 | + |
| 134 | + # StartInterval is not available in the config object |
| 135 | + create_obj = inspect[0]["Config"]["CreateCommand"] |
| 136 | + self.assertIn("--health-startup-interval", create_obj) |
0 commit comments