Skip to content

Commit 13d2dc5

Browse files
committed
fix unittest failures after adding _config_hash
Signed-off-by: Songmin Li <lisongmin@protonmail.com>
1 parent 312d321 commit 13d2dc5

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

podman_compose.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,13 +2139,18 @@ def config_hash(self, service: dict[str, Any]) -> str:
21392139
return service["_config_hash"]
21402140

21412141
# Use a stable representation of the service configuration
2142-
jsonable_servcie = {
2143-
k: v for k, v in service.items() if isinstance(k, str) and not k.startswith("_")
2144-
}
2142+
jsonable_servcie = self.original_service(service)
21452143
config_str = json.dumps(jsonable_servcie, sort_keys=True)
21462144
service["_config_hash"] = hashlib.sha256(config_str.encode('utf-8')).hexdigest()
21472145
return service["_config_hash"]
21482146

2147+
def original_service(self, service: dict[str, Any]) -> dict[str, Any]:
2148+
"""
2149+
Returns the original service configuration without any overrides or resets.
2150+
This is used to compare the original service configuration with the current one.
2151+
"""
2152+
return {k: v for k, v in service.items() if isinstance(k, str) and not k.startswith("_")}
2153+
21492154
def resolve_pod_name(self) -> str | None:
21502155
# Priorities:
21512156
# - Command line --in-pod

tests/unit/test_can_merge_build.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ def test_parse_compose_file_when_multiple_composes(self, input, override, expect
9292

9393
actual_compose = {}
9494
if podman_compose.services:
95-
podman_compose.services["test-service"].pop("_deps")
96-
actual_compose = podman_compose.services["test-service"]
95+
actual_compose = podman_compose.original_service(
96+
podman_compose.services["test-service"]
97+
)
9798
self.assertEqual(actual_compose, expected)
9899

99100
# $$$ is a placeholder for either command or entrypoint
@@ -138,8 +139,7 @@ def test_parse_compose_file_when_multiple_composes_keys_command_entrypoint(
138139

139140
actual = {}
140141
if podman_compose.services:
141-
podman_compose.services["test-service"].pop("_deps")
142-
actual = podman_compose.services["test-service"]
142+
actual = podman_compose.original_service(podman_compose.services["test-service"])
143143
self.assertEqual(actual, expected)
144144

145145

tests/unit/test_normalize_final_build.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ def test_parse_compose_file_when_single_compose(self, input, expected):
123123

124124
actual_compose = {}
125125
if podman_compose.services:
126-
podman_compose.services["test-service"].pop("_deps")
127-
actual_compose = podman_compose.services["test-service"]
126+
actual_compose = podman_compose.original_service(
127+
podman_compose.services["test-service"]
128+
)
128129
self.assertEqual(actual_compose, expected)
129130

130131
@parameterized.expand([
@@ -238,8 +239,9 @@ def test_parse_when_multiple_composes(self, input, override, expected):
238239

239240
actual_compose = {}
240241
if podman_compose.services:
241-
podman_compose.services["test-service"].pop("_deps")
242-
actual_compose = podman_compose.services["test-service"]
242+
actual_compose = podman_compose.original_service(
243+
podman_compose.services["test-service"]
244+
)
243245
self.assertEqual(actual_compose, expected)
244246

245247

0 commit comments

Comments
 (0)