Skip to content

Commit

Permalink
Unit test for healthcheck block
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Syl <robin@robinsyl.dev>
  • Loading branch information
recursiveribbons committed Mar 11, 2024
1 parent 540105d commit 34de89f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/healthcheck/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3"
services:
healthcheck:
image: nopush/podman-compose-test
healthcheck:
test: [ "CMD-SHELL", "curl -f http://localhost || exit 1" ]
interval: 1m
timeout: 10s
retries: 3
start_period: 10s
start_interval: 5s
45 changes: 45 additions & 0 deletions tests/test_podman_compose_up_down.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

# pylint: disable=redefined-outer-name
import json
import os
import unittest

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

self.assertEqual(expected_services, actual_services)

def test_healthcheck(self):
up_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
os.path.join(test_path(), "healthcheck", "docker-compose.yml"),
"up",
"-d",
]
self.run_subprocess_assert_returncode(up_cmd)

command_container_id = [
"podman",
"ps",
"-a",
"--filter",
"label=io.podman.compose.project=healthcheck",
"--format",
'"{{.ID}}"',
]
out, _ = self.run_subprocess_assert_returncode(command_container_id)
self.assertNotEqual(out, b"")
container_id = out.decode("utf-8").strip().replace('"', "")

command_inspect = ["podman", "container", "inspect", container_id]

out, _ = self.run_subprocess_assert_returncode(command_inspect)
out_string = out.decode("utf-8")
inspect = json.loads(out_string)
healthcheck_obj = inspect[0]["Config"]["Healthcheck"]
expected = {
"Test": ["CMD-SHELL", "/bin/sh -c 'curl -f http://localhost || exit 1'"],
"StartPeriod": 10000000000,
"Interval": 60000000000,
"Timeout": 10000000000,
"Retries": 3,
}
self.assertEqual(healthcheck_obj, expected)

# StartInterval is not available in the config object
create_obj = inspect[0]["Config"]["CreateCommand"]
self.assertIn("--health-startup-interval", create_obj)

0 comments on commit 34de89f

Please sign in to comment.