mirror of
https://github.com/containers/podman-compose.git
synced 2025-03-10 13:08:13 +01:00
Add unit test for depends_on normalization as a dict
Signed-off-by: Hedayat Vatankhah <hedayat.fwd@gmail.com>
This commit is contained in:
parent
c31b4e2816
commit
1f35c00694
@ -1281,7 +1281,7 @@ def normalize_service(service, sub_dir=""):
|
|||||||
if is_str(deps):
|
if is_str(deps):
|
||||||
deps = [deps]
|
deps = [deps]
|
||||||
if is_list(deps):
|
if is_list(deps):
|
||||||
deps_dict = dict()
|
deps_dict = {}
|
||||||
for d in deps:
|
for d in deps:
|
||||||
deps_dict[d] = {'condition': 'service_started'}
|
deps_dict[d] = {'condition': 'service_started'}
|
||||||
service["depends_on"] = deps_dict
|
service["depends_on"] = deps_dict
|
||||||
|
43
pytests/test_normalize_depends_on.py
Normal file
43
pytests/test_normalize_depends_on.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import copy
|
||||||
|
|
||||||
|
from podman_compose import normalize_service
|
||||||
|
|
||||||
|
test_cases_simple = [
|
||||||
|
(
|
||||||
|
{"depends_on": "my_service"},
|
||||||
|
{"depends_on": {"my_service": {"condition": "service_started"}}},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
{"depends_on": ["my_service"]},
|
||||||
|
{"depends_on": {"my_service": {"condition": "service_started"}}},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
{"depends_on": ["my_service1", "my_service2"]},
|
||||||
|
{
|
||||||
|
"depends_on": {
|
||||||
|
"my_service1": {"condition": "service_started"},
|
||||||
|
"my_service2": {"condition": "service_started"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
{"depends_on": {"my_service": {"condition": "service_started"}}},
|
||||||
|
{"depends_on": {"my_service": {"condition": "service_started"}}},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
{"depends_on": {"my_service": {"condition": "service_healthy"}}},
|
||||||
|
{"depends_on": {"my_service": {"condition": "service_healthy"}}},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_normalize_service_simple():
|
||||||
|
for test_case, expected in copy.deepcopy(test_cases_simple):
|
||||||
|
test_original = copy.deepcopy(test_case)
|
||||||
|
test_case = normalize_service(test_case)
|
||||||
|
test_result = expected == test_case
|
||||||
|
if not test_result:
|
||||||
|
print("test: ", test_original)
|
||||||
|
print("expected: ", expected)
|
||||||
|
print("actual: ", test_case)
|
||||||
|
assert test_result
|
Loading…
Reference in New Issue
Block a user