|
| 1 | +# SPDX-License-Identifier: GPL-2.0 |
| 2 | + |
| 3 | +import json |
| 4 | +import os |
| 5 | +import unittest |
| 6 | + |
| 7 | +from tests.integration.test_utils import RunSubprocessMixin |
| 8 | +from tests.integration.test_utils import podman_compose_path |
| 9 | +from tests.integration.test_utils import test_path |
| 10 | + |
| 11 | + |
| 12 | +def compose_yaml_path(): |
| 13 | + return os.path.join(os.path.join(test_path(), "override_tag_attribute"), "docker-compose.yaml") |
| 14 | + |
| 15 | + |
| 16 | +class TestComposeOverrideTagAttribute(unittest.TestCase, RunSubprocessMixin): |
| 17 | + # test if a service attribute from docker-compose.yaml file is overridden |
| 18 | + def test_override_tag_attribute(self): |
| 19 | + override_file = os.path.join( |
| 20 | + os.path.join(test_path(), "override_tag_attribute"), |
| 21 | + "docker-compose.override_attribute.yaml", |
| 22 | + ) |
| 23 | + try: |
| 24 | + self.run_subprocess_assert_returncode([ |
| 25 | + podman_compose_path(), |
| 26 | + "-f", |
| 27 | + compose_yaml_path(), |
| 28 | + "-f", |
| 29 | + override_file, |
| 30 | + "up", |
| 31 | + ]) |
| 32 | + # merge rules are still applied |
| 33 | + output, _ = self.run_subprocess_assert_returncode([ |
| 34 | + podman_compose_path(), |
| 35 | + "-f", |
| 36 | + compose_yaml_path(), |
| 37 | + "-f", |
| 38 | + override_file, |
| 39 | + "logs", |
| 40 | + ]) |
| 41 | + self.assertEqual(output, b"One\n") |
| 42 | + |
| 43 | + # only app service attribute "ports" was overridden |
| 44 | + output, _ = self.run_subprocess_assert_returncode([ |
| 45 | + "podman", |
| 46 | + "inspect", |
| 47 | + "override_tag_attribute_app_1", |
| 48 | + ]) |
| 49 | + container_info = json.loads(output.decode('utf-8'))[0] |
| 50 | + self.assertEqual( |
| 51 | + container_info['NetworkSettings']["Ports"], |
| 52 | + {"81/tcp": [{"HostIp": "", "HostPort": "8111"}]}, |
| 53 | + ) |
| 54 | + finally: |
| 55 | + self.run_subprocess_assert_returncode([ |
| 56 | + podman_compose_path(), |
| 57 | + "-f", |
| 58 | + compose_yaml_path(), |
| 59 | + "down", |
| 60 | + ]) |
0 commit comments