add test case for when build is a complex dictionary

Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
This commit is contained in:
Sergei Biriukov 2023-04-30 15:37:52 +10:00
parent a0005db474
commit 8c66b1cda7
2 changed files with 17 additions and 5 deletions

View File

@ -1296,10 +1296,7 @@ def parse_build(build):
if is_str(build):
build_parsed["context"] = build
elif is_dict(build):
if "context" in build:
build_parsed["context"] = build["context"]
if "dockerfile" in build:
build_parsed["dockerfile"] = build["dockerfile"]
build_parsed = build
else:
raise ValueError(f"invalid type of build value [{type(build)}]")
return build_parsed
@ -1326,7 +1323,7 @@ def rec_merge_one(target, source):
source_parsed = {}
if key in source:
source_parsed = parse_build(source[key])
target["build"] = {**target_parsed, **source_parsed}
target["build"] = rec_merge_one(target_parsed, source_parsed)
continue
if key not in source:
continue

View File

@ -40,6 +40,21 @@ test_cases = [
{"build": {"dockerfile": "./compose-2.yaml", "context": "./dir-2"}},
{"build": {"dockerfile": "./compose-2.yaml", "context": "./dir-2"}},
),
(
{"build": {"dockerfile": "./compose-1.yaml"}},
{"build": {"dockerfile": "./compose-2.yaml", "args": ["ENV1=1"]}},
{"build": {"dockerfile": "./compose-2.yaml", "args": ["ENV1=1"]}},
),
(
{"build": {"dockerfile": "./compose-2.yaml", "args": ["ENV1=1"]}},
{"build": {"dockerfile": "./compose-1.yaml"}},
{"build": {"dockerfile": "./compose-1.yaml", "args": ["ENV1=1"]}},
),
(
{"build": {"dockerfile": "./compose-2.yaml", "args": ["ENV1=1"]}},
{"build": {"dockerfile": "./compose-1.yaml", "args": ["ENV2=2"]}},
{"build": {"dockerfile": "./compose-1.yaml", "args": ["ENV1=1", "ENV2=2"]}},
),
]