Skip to content

Commit 34f5268

Browse files
lisongminp12tic
authored andcommitted
Add unittest for rec_subs
Signed-off-by: Songmin Li <[email protected]>
1 parent b5eaf31 commit 34f5268

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/unit/test_rec_subs.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
# pylint: disable=protected-access
3+
4+
import unittest
5+
6+
from parameterized import parameterized
7+
8+
from podman_compose import rec_subs
9+
10+
11+
class TestRecSubs(unittest.TestCase):
12+
substitutions = [
13+
# dict with environment variables
14+
(
15+
"service's environment is low priority",
16+
{"environment": {"v1": "low priority", "actual-v1": "$v1"}},
17+
{"environment": {"v1": "low priority", "actual-v1": "high priority"}},
18+
),
19+
(
20+
"service's environment can be used in other values",
21+
{"environment": {"v100": "v1.0.0", "image": "abc:$v100"}},
22+
{"environment": {"v100": "v1.0.0", "image": "abc:v1.0.0"}},
23+
),
24+
(
25+
"Non-variable should not be substituted",
26+
{"environment": {"non_var": "$$v1", "vx": "$non_var"}, "image": "abc:$non_var"},
27+
{"environment": {"non_var": "$v1", "vx": "$v1"}, "image": "abc:$v1"},
28+
),
29+
# list
30+
(
31+
"Values in list are substituted",
32+
["$v1", "low priority"],
33+
["high priority", "low priority"],
34+
),
35+
# str
36+
(
37+
"Value with ${VARIABLE} format",
38+
"${v1}",
39+
"high priority",
40+
),
41+
(
42+
"Value with ${VARIABLE:-default} format",
43+
["${v1:-default}", "${empty:-default}", "${not_exits:-default}"],
44+
["high priority", "default", "default"],
45+
),
46+
(
47+
"Value with ${VARIABLE-default} format",
48+
["${v1-default}", "${empty-default}", "${not_exits-default}"],
49+
["high priority", "", "default"],
50+
),
51+
(
52+
"Value $$ means $",
53+
"$$v1",
54+
"$v1",
55+
),
56+
]
57+
58+
@parameterized.expand(substitutions)
59+
def test_rec_subs(self, desc, input, expected):
60+
sub_dict = {"v1": "high priority", "empty": ""}
61+
result = rec_subs(input, sub_dict)
62+
self.assertEqual(result, expected, msg=desc)

0 commit comments

Comments
 (0)