Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 338f44b

Browse filesBrowse files
Unit tests for healthcheck block
1 parent a86b6e4 commit 338f44b
Copy full SHA for 338f44b

File tree

Expand file treeCollapse file tree

2 files changed

+56
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+56
-0
lines changed

‎tests/healthcheck/docker-compose.yml

Copy file name to clipboard
+11Lines 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

‎tests/test_podman_compose_up_down.py

Copy file name to clipboardExpand all lines: tests/test_podman_compose_up_down.py
+45Lines changed: 45 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.