From 1f35c00694bfcda04f10a18d0209303547b8e785 Mon Sep 17 00:00:00 2001 From: Hedayat Vatankhah Date: Mon, 8 Apr 2024 23:02:25 +0330 Subject: [PATCH] Add unit test for depends_on normalization as a dict Signed-off-by: Hedayat Vatankhah --- podman_compose.py | 2 +- pytests/test_normalize_depends_on.py | 43 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 pytests/test_normalize_depends_on.py diff --git a/podman_compose.py b/podman_compose.py index 4917795..c7457a1 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1281,7 +1281,7 @@ def normalize_service(service, sub_dir=""): if is_str(deps): deps = [deps] if is_list(deps): - deps_dict = dict() + deps_dict = {} for d in deps: deps_dict[d] = {'condition': 'service_started'} service["depends_on"] = deps_dict diff --git a/pytests/test_normalize_depends_on.py b/pytests/test_normalize_depends_on.py new file mode 100644 index 0000000..de773e6 --- /dev/null +++ b/pytests/test_normalize_depends_on.py @@ -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