2024-03-08 11:19:12 +01:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
2022-11-09 18:21:25 +01:00
|
|
|
"""
|
|
|
|
test_podman_compose_config.py
|
|
|
|
|
|
|
|
Tests the podman-compose config command which is used to return defined compose services.
|
|
|
|
"""
|
2024-03-07 17:28:06 +01:00
|
|
|
|
2023-04-10 12:38:21 +02:00
|
|
|
# pylint: disable=redefined-outer-name
|
2022-11-09 18:21:25 +01:00
|
|
|
import os
|
2024-03-08 22:46:19 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from parameterized import parameterized
|
|
|
|
|
2024-07-03 18:30:40 +02:00
|
|
|
from tests.integration.test_podman_compose import podman_compose_path
|
|
|
|
from tests.integration.test_podman_compose import test_path
|
|
|
|
from tests.integration.test_utils import RunSubprocessMixin
|
2022-11-09 18:21:25 +01:00
|
|
|
|
|
|
|
|
2024-03-08 10:00:34 +01:00
|
|
|
def profile_compose_file():
|
2022-11-09 18:59:28 +01:00
|
|
|
""" "Returns the path to the `profile` compose file used for this test module"""
|
2024-03-08 10:00:34 +01:00
|
|
|
return os.path.join(test_path(), "profile", "docker-compose.yml")
|
|
|
|
|
|
|
|
|
2024-03-08 12:14:02 +01:00
|
|
|
class TestComposeConfig(unittest.TestCase, RunSubprocessMixin):
|
2024-03-08 10:00:34 +01:00
|
|
|
def test_config_no_profiles(self):
|
|
|
|
"""
|
|
|
|
Tests podman-compose config command without profile enablement.
|
|
|
|
"""
|
|
|
|
config_cmd = [
|
|
|
|
"coverage",
|
|
|
|
"run",
|
|
|
|
podman_compose_path(),
|
|
|
|
"-f",
|
|
|
|
profile_compose_file(),
|
|
|
|
"config",
|
|
|
|
]
|
|
|
|
|
2024-03-08 12:14:02 +01:00
|
|
|
out, _ = self.run_subprocess_assert_returncode(config_cmd)
|
2024-03-08 10:00:34 +01:00
|
|
|
|
|
|
|
string_output = out.decode("utf-8")
|
|
|
|
self.assertIn("default-service", string_output)
|
|
|
|
self.assertNotIn("service-1", string_output)
|
|
|
|
self.assertNotIn("service-2", string_output)
|
|
|
|
|
|
|
|
@parameterized.expand(
|
|
|
|
[
|
|
|
|
(
|
|
|
|
["--profile", "profile-1", "config"],
|
|
|
|
{"default-service": True, "service-1": True, "service-2": False},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
["--profile", "profile-2", "config"],
|
|
|
|
{"default-service": True, "service-1": False, "service-2": True},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
["--profile", "profile-1", "--profile", "profile-2", "config"],
|
|
|
|
{"default-service": True, "service-1": True, "service-2": True},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_config_profiles(self, profiles, expected_services):
|
|
|
|
"""
|
|
|
|
Tests podman-compose
|
|
|
|
:param profiles: The enabled profiles for the parameterized test.
|
2024-03-08 22:46:24 +01:00
|
|
|
:param expected_services: Dictionary used to model the expected "enabled" services in the
|
|
|
|
profile. Key = service name, Value = True if the service is enabled, otherwise False.
|
2024-03-08 10:00:34 +01:00
|
|
|
"""
|
|
|
|
config_cmd = ["coverage", "run", podman_compose_path(), "-f", profile_compose_file()]
|
|
|
|
config_cmd.extend(profiles)
|
|
|
|
|
2024-03-08 12:14:02 +01:00
|
|
|
out, _ = self.run_subprocess_assert_returncode(config_cmd)
|
2024-03-08 10:00:34 +01:00
|
|
|
|
|
|
|
actual_output = out.decode("utf-8")
|
|
|
|
|
|
|
|
self.assertEqual(len(expected_services), 3)
|
|
|
|
|
|
|
|
actual_services = {}
|
|
|
|
for service, _ in expected_services.items():
|
|
|
|
actual_services[service] = service in actual_output
|
|
|
|
|
|
|
|
self.assertEqual(expected_services, actual_services)
|