Skip to content

Commit 7fc414f

Browse files
recursiveribbonsmokibit
authored andcommitted
tests/integration: Add tests for healthcheck block
Signed-off-by: Robin Syl <[email protected]> Signed-off-by: Monika Kairaityte <[email protected]>
1 parent d980b55 commit 7fc414f

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 11 additions & 0 deletions
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
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

Comments
 (0)