Skip to content

Commit 34de89f

Browse files
Unit test for healthcheck block
Signed-off-by: Robin Syl <[email protected]>
1 parent 540105d commit 34de89f

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

tests/healthcheck/docker-compose.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "3"
2+
services:
3+
healthcheck:
4+
image: nopush/podman-compose-test
5+
healthcheck:
6+
test: [ "CMD-SHELL", "curl -f http://localhost || exit 1" ]
7+
interval: 1m
8+
timeout: 10s
9+
retries: 3
10+
start_period: 10s
11+
start_interval: 5s

tests/test_podman_compose_up_down.py

+45
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
# pylint: disable=redefined-outer-name
10+
import json
1011
import os
1112
import unittest
1213

@@ -89,3 +90,47 @@ def test_up(self, profiles, expected_services):
8990
actual_services[service] = service in actual_output
9091

9192
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

Comments
 (0)