Skip to content

Commit 6306e19

Browse files
committed
Add integration test for compose down
Signed-off-by: Songmin Li <lisongmin@protonmail.com>
1 parent 967bced commit 6306e19

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

tests/integration/compose_down_behavior/__init__.py

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
app:
3+
image: nopush/podman-compose-test
4+
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-p", "8080"]
5+
depends_on:
6+
- db
7+
db:
8+
image: nopush/podman-compose-test
9+
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-p", "8080"]
10+
no_deps:
11+
image: nopush/podman-compose-test
12+
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-p", "8080"]
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
import os
4+
import unittest
5+
6+
from parameterized import parameterized
7+
8+
from tests.integration.test_utils import RunSubprocessMixin
9+
from tests.integration.test_utils import podman_compose_path
10+
from tests.integration.test_utils import test_path
11+
12+
13+
def compose_yaml_path(scenario: str) -> str:
14+
return os.path.join(
15+
os.path.join(test_path(), "compose_down_behavior"), f"docker-compose_{scenario}.yaml"
16+
)
17+
18+
19+
class TestComposeDownBehavior(unittest.TestCase, RunSubprocessMixin):
20+
@parameterized.expand([
21+
("default", ["down"], {}),
22+
(
23+
"default",
24+
["down", "app"],
25+
{
26+
"compose_down_behavior_db_1": "running",
27+
"compose_down_behavior_no_deps_1": "running",
28+
},
29+
),
30+
(
31+
"default",
32+
["down", "db"],
33+
{
34+
"compose_down_behavior_no_deps_1": "running",
35+
},
36+
),
37+
])
38+
def test_compose_down(
39+
self, scenario: str, command_args: list[str], expect_containers: dict[str, str]
40+
) -> None:
41+
try:
42+
self.run_subprocess_assert_returncode(
43+
[podman_compose_path(), "-f", compose_yaml_path(scenario), "up", "-d"],
44+
)
45+
46+
self.run_subprocess_assert_returncode(
47+
[
48+
podman_compose_path(),
49+
"-f",
50+
compose_yaml_path(scenario),
51+
*command_args,
52+
],
53+
)
54+
55+
out, _ = self.run_subprocess_assert_returncode(
56+
[
57+
podman_compose_path(),
58+
"-f",
59+
compose_yaml_path(scenario),
60+
"ps",
61+
"--format",
62+
'{{ .Names }} {{ .State }}',
63+
],
64+
)
65+
66+
actual_containers = {}
67+
for line in out.decode('utf-8').strip().split('\n'):
68+
if line:
69+
try:
70+
name, state = line.split()
71+
actual_containers[name] = state
72+
except ValueError as e:
73+
print(f"Error parsing line '{line}': {e}")
74+
raise e
75+
76+
self.assertEqual(actual_containers, expect_containers)
77+
finally:
78+
self.run_subprocess_assert_returncode([
79+
podman_compose_path(),
80+
"-f",
81+
compose_yaml_path(scenario),
82+
"down",
83+
"-t",
84+
"0",
85+
])

0 commit comments

Comments
 (0)