Skip to content

Commit f4eec92

Browse files
Add comprehensive tests for KVP splitting to prevent issue #35 regression
Co-authored-by: smurawski <4006985+smurawski@users.noreply.github.com>
1 parent 9cdc89f commit f4eec92

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/tests/service/test_service_environment.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from unittest import TestCase
22

33
from pycomposefile import compose_file
4+
from pycomposefile.compose_element.compose_list_or_map import ComposeListOrMapElement
45

56
from ..compose_generator import ComposeGenerator
67

@@ -19,3 +20,38 @@ def test_service_with_environment_list(self):
1920
self.assertEqual(compose_file.services["frontend"].environment["RACK_ENV"], "development")
2021
self.assertEqual(compose_file.services["frontend"].environment["SHOW"], "true")
2122
self.assertIsNone(compose_file.services["frontend"].environment["USER_INPUT"])
23+
24+
def test_kvp_with_multiple_equals_issue_35(self):
25+
"""Test for issue #35: KVP strings with multiple '=' should split on first '=' only"""
26+
# Test the exact scenario from the issue
27+
element = ComposeListOrMapElement("JAVA_OPTS=foo=bar&&baz=buzz")
28+
self.assertEqual(element["JAVA_OPTS"], "foo=bar&&baz=buzz")
29+
30+
def test_kvp_splitting_edge_cases(self):
31+
"""Test various edge cases for KVP splitting to prevent regression"""
32+
test_cases = [
33+
# (input_string, expected_key, expected_value)
34+
("KEY=value", "KEY", "value"),
35+
("KEY=value=extra", "KEY", "value=extra"),
36+
("KEY=a=b=c=d", "KEY", "a=b=c=d"),
37+
("URL=http://example.com:8080/path?param=value", "URL", "http://example.com:8080/path?param=value"),
38+
("CONFIG=key1=val1,key2=val2", "CONFIG", "key1=val1,key2=val2"),
39+
("COMPLEX=a=b&c=d&e=f", "COMPLEX", "a=b&c=d&e=f"),
40+
("NO_VALUE", "NO_VALUE", None),
41+
]
42+
43+
for input_string, expected_key, expected_value in test_cases:
44+
with self.subTest(input=input_string):
45+
element = ComposeListOrMapElement(input_string)
46+
self.assertEqual(element[expected_key], expected_value)
47+
48+
def test_empty_value_handling(self):
49+
"""Test handling of empty values - this is existing behavior that should be preserved"""
50+
# EMPTY= should result in None (existing behavior)
51+
element = ComposeListOrMapElement("EMPTY=")
52+
self.assertIsNone(element["EMPTY"])
53+
54+
# Test the isValueEmpty method directly
55+
element_test = ComposeListOrMapElement(None)
56+
self.assertTrue(element_test.isValueEmpty("KEY="))
57+
self.assertFalse(element_test.isValueEmpty("KEY=value"))

0 commit comments

Comments
 (0)