Skip to content

Commit c8f757c

Browse files
recursiveribbonsmokibit
authored andcommitted
tests/integration: Add tests for healthcheck block
Co-authored-by: Robin Syl <robin@robinsyl.dev> Co-authored-by: Monika Kairaityte <monika@kibit.lt> Signed-off-by: Robin Syl <robin@robinsyl.dev> Signed-off-by: Monika Kairaityte <monika@kibit.lt>
1 parent 765d16d commit c8f757c

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
healthcheck:
3+
image: nopush/podman-compose-test
4+
healthcheck:
5+
test: [ "CMD-SHELL", "curl -f http://localhost || exit 1" ]
6+
interval: 1m
7+
timeout: 10s
8+
retries: 3
9+
start_period: 10s
10+
start_interval: 5s
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
class TestHealthcheck(unittest.TestCase, RunSubprocessMixin):
13+
def test_healthcheck(self) -> None:
14+
compose_path = os.path.join(os.path.join(test_path(), "healthcheck"), "docker-compose.yml")
15+
16+
try:
17+
self.run_subprocess_assert_returncode([
18+
"coverage",
19+
"run",
20+
podman_compose_path(),
21+
"-f",
22+
compose_path,
23+
"up",
24+
"-d",
25+
])
26+
27+
out, _ = self.run_subprocess_assert_returncode([
28+
"podman",
29+
"ps",
30+
"-a",
31+
"--filter",
32+
"label=io.podman.compose.project=healthcheck",
33+
"--format",
34+
'"{{.ID}}"',
35+
])
36+
self.assertNotEqual(out, b"")
37+
38+
container_id = out.decode("utf-8").strip().replace('"', "")
39+
out, _ = self.run_subprocess_assert_returncode([
40+
"podman",
41+
"container",
42+
"inspect",
43+
container_id,
44+
])
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)
60+
61+
finally:
62+
out, _ = self.run_subprocess_assert_returncode([
63+
podman_compose_path(),
64+
"-f",
65+
compose_path,
66+
"down",
67+
])

0 commit comments

Comments
 (0)