mirror of
https://github.com/containers/podman-compose.git
synced 2025-02-15 01:41:03 +01:00
Also modifies an existing integration test to expect an empty string as `docker-compose` warns that `ZZVAR3` is not set and defaults it to an empty string per the acutal output here. ```yaml $ docker-compose -f container-compose.load-.env-in-project.yaml config WARN[0000] The "ZZVAR3" variable is not set. Defaulting to a blank string. name: project services: app: command: - /bin/busybox - sh - -c - env | grep ZZ environment: ZZVAR1: This value is loaded but should be overwritten ZZVAR2: This value is loaded from .env in project/ directory ZZVAR3: "" ... ``` Signed-off-by: indra <indra.talip@gmail.com>
73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
# SPDX-License-Identifier: GPL-2.0
|
|
# pylint: disable=protected-access
|
|
|
|
import unittest
|
|
|
|
from parameterized import parameterized
|
|
|
|
from podman_compose import rec_subs
|
|
|
|
|
|
class TestRecSubs(unittest.TestCase):
|
|
substitutions = [
|
|
# dict with environment variables
|
|
(
|
|
"service's environment is low priority",
|
|
{"environment": {"v1": "low priority", "actual-v1": "$v1"}},
|
|
{"environment": {"v1": "low priority", "actual-v1": "high priority"}},
|
|
),
|
|
(
|
|
"service's environment can be used in other values",
|
|
{"environment": {"v100": "v1.0.0", "image": "abc:$v100"}},
|
|
{"environment": {"v100": "v1.0.0", "image": "abc:v1.0.0"}},
|
|
),
|
|
(
|
|
"Non-variable should not be substituted",
|
|
{"environment": {"non_var": "$$v1", "vx": "$non_var"}, "image": "abc:$non_var"},
|
|
{"environment": {"non_var": "$v1", "vx": "$v1"}, "image": "abc:$v1"},
|
|
),
|
|
(
|
|
"service environment with unpopulated ${VARIABLE:-default} format",
|
|
{"environment": {"v100": "${v100:-low priority}", "actual-v100": "$v100"}},
|
|
{"environment": {"v100": "low priority", "actual-v100": "low priority"}},
|
|
),
|
|
(
|
|
"service environment with populated ${VARIABLE:-default} format",
|
|
{"environment": {"v1": "${v1:-low priority}", "actual-v1": "$v1"}},
|
|
{"environment": {"v1": "high priority", "actual-v1": "high priority"}},
|
|
),
|
|
# list
|
|
(
|
|
"Values in list are substituted",
|
|
["$v1", "low priority"],
|
|
["high priority", "low priority"],
|
|
),
|
|
# str
|
|
(
|
|
"Value with ${VARIABLE} format",
|
|
"${v1}",
|
|
"high priority",
|
|
),
|
|
(
|
|
"Value with ${VARIABLE:-default} format",
|
|
["${v1:-default}", "${empty:-default}", "${not_exits:-default}"],
|
|
["high priority", "default", "default"],
|
|
),
|
|
(
|
|
"Value with ${VARIABLE-default} format",
|
|
["${v1-default}", "${empty-default}", "${not_exits-default}"],
|
|
["high priority", "", "default"],
|
|
),
|
|
(
|
|
"Value $$ means $",
|
|
"$$v1",
|
|
"$v1",
|
|
),
|
|
]
|
|
|
|
@parameterized.expand(substitutions)
|
|
def test_rec_subs(self, desc, input, expected):
|
|
sub_dict = {"v1": "high priority", "empty": ""}
|
|
result = rec_subs(input, sub_dict)
|
|
self.assertEqual(result, expected, msg=desc)
|