Skip to content

Commit cd25efa

Browse files
committed
Add integration test for compose down
Signed-off-by: Songmin Li <[email protected]>
1 parent 967bced commit cd25efa

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-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: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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"], set()),
22+
(
23+
"default",
24+
["down", "app"],
25+
{
26+
"compose_down_behavior_db_1",
27+
"compose_down_behavior_no_deps_1",
28+
},
29+
),
30+
(
31+
"default",
32+
["down", "db"],
33+
{
34+
"compose_down_behavior_no_deps_1",
35+
},
36+
),
37+
])
38+
def test_compose_down(
39+
self, scenario: str, command_args: list[str], expect_containers: set[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 }}',
63+
],
64+
)
65+
66+
actual_containers = set()
67+
for line in out.decode('utf-8').strip().split('\n'):
68+
name = line.strip()
69+
if name:
70+
actual_containers.add(name)
71+
72+
self.assertEqual(actual_containers, expect_containers)
73+
finally:
74+
self.run_subprocess_assert_returncode([
75+
podman_compose_path(),
76+
"-f",
77+
compose_yaml_path(scenario),
78+
"down",
79+
"-t",
80+
"0",
81+
])

0 commit comments

Comments
 (0)