|
| 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