| 1 |
|
| 2 |
|
| 3 |
""" |
| 4 |
test_podman_compose_config.py |
| 5 |
|
| 6 |
Tests the podman-compose config command which is used to return defined compose services. |
| 7 |
""" |
| 8 |
|
| 9 |
|
| 10 |
import os |
| 11 |
import unittest |
| 12 |
|
| 13 |
from parameterized import parameterized |
| 14 |
|
| 15 |
from tests.integration.test_utils import RunSubprocessMixin |
| 16 |
from tests.integration.test_utils import podman_compose_path |
| 17 |
from tests.integration.test_utils import test_path |
| 18 |
|
| 19 |
|
| 20 |
def profile_compose_file() -> str: |
| 21 |
""" "Returns the path to the `profile` compose file used for this test module""" |
| 22 |
return os.path.join(test_path(), "profile", "docker-compose.yml") |
| 23 |
|
| 24 |
|
| 25 |
class TestComposeConfig(unittest.TestCase, RunSubprocessMixin): |
| 26 |
def test_config_no_profiles(self) -> None: |
| 27 |
""" |
| 28 |
Tests podman-compose config command without profile enablement. |
| 29 |
""" |
| 30 |
config_cmd = [ |
| 31 |
"coverage", |
| 32 |
"run", |
| 33 |
podman_compose_path(), |
| 34 |
"-f", |
| 35 |
profile_compose_file(), |
| 36 |
"config", |
| 37 |
] |
| 38 |
|
| 39 |
out, _ = self.run_subprocess_assert_returncode(config_cmd) |
| 40 |
|
| 41 |
string_output = out.decode("utf-8") |
| 42 |
self.assertIn("default-service", string_output) |
| 43 |
self.assertNotIn("service-1", string_output) |
| 44 |
self.assertNotIn("service-2", string_output) |
| 45 |
|
| 46 |
@parameterized.expand( |
| 47 |
[ |
| 48 |
( |
| 49 |
["--profile", "profile-1", "config"], |
| 50 |
{"default-service": True, "service-1": True, "service-2": False}, |
| 51 |
), |
| 52 |
( |
| 53 |
["--profile", "profile-2", "config"], |
| 54 |
{"default-service": True, "service-1": False, "service-2": True}, |
| 55 |
), |
| 56 |
( |
| 57 |
["--profile", "profile-1", "--profile", "profile-2", "config"], |
| 58 |
{"default-service": True, "service-1": True, "service-2": True}, |
| 59 |
), |
| 60 |
], |
| 61 |
) |
| 62 |
def test_config_profiles(self, profiles: list, expected_services: dict) -> None: |
| 63 |
""" |
| 64 |
Tests podman-compose |
| 65 |
:param profiles: The enabled profiles for the parameterized test. |
| 66 |
:param expected_services: Dictionary used to model the expected "enabled" services in the |
| 67 |
profile. Key = service name, Value = True if the service is enabled, otherwise False. |
| 68 |
""" |
| 69 |
config_cmd = ["coverage", "run", podman_compose_path(), "-f", profile_compose_file()] |
| 70 |
config_cmd.extend(profiles) |
| 71 |
|
| 72 |
out, _ = self.run_subprocess_assert_returncode(config_cmd) |
| 73 |
|
| 74 |
actual_output = out.decode("utf-8") |
| 75 |
|
| 76 |
self.assertEqual(len(expected_services), 3) |
| 77 |
|
| 78 |
actual_services = {} |
| 79 |
for service, _ in expected_services.items(): |
| 80 |
actual_services[service] = service in actual_output |
| 81 |
|
| 82 |
self.assertEqual(expected_services, actual_services) |