Skip to content

Commit 7ddb572

Browse files
committed
test: Add backend error handling tests for Value class
- Add test_get_value_backend_error to verify RuntimeError propagation - Add test_set_value_backend_error to verify RuntimeError propagation - Fix type validation in Value.set method
1 parent 854041f commit 7ddb572

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

helm_values_manager/models/value.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ def set(self, value: Union[str, int, float, bool, None]) -> None:
5757
Set the value using the backend.
5858
5959
Args:
60-
value: The value to store, can be a raw value, a secret reference, or None
60+
value: The value to store, can be a string, number, boolean, or None
6161
6262
Raises:
63-
ValueError: If value is not a string, number, boolean, or None
63+
ValueError: If the value is not a string, number, boolean, or None
6464
RuntimeError: If backend operation fails
6565
"""
6666
if not isinstance(value, (str, int, float, bool, type(None))):
@@ -71,6 +71,7 @@ def set(self, value: Union[str, int, float, bool, None]) -> None:
7171
HelmLogger.debug("Successfully set value for path %s", self.path)
7272
except Exception as e:
7373
HelmLogger.error("Failed to set value for path %s in environment %s: %s", self.path, self.environment, e)
74+
HelmLogger.error("Error setting value: %s", e)
7475
raise
7576

7677
def to_dict(self) -> Dict[str, Any]:

tests/unit/models/test_value.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,28 @@ def test_set_invalid_type(mock_backend):
8181
value.set({"key": "value"}) # Dictionary is not a valid type
8282

8383

84+
def test_get_value_backend_error(mock_backend):
85+
"""Test error handling when backend.get_value raises an exception."""
86+
mock_backend.get_value.side_effect = RuntimeError("Backend error")
87+
value = Value(path="app.replicas", environment="dev", _backend=mock_backend)
88+
89+
with pytest.raises(RuntimeError, match="Backend error"):
90+
value.get()
91+
92+
mock_backend.get_value.assert_called_once_with("app.replicas", "dev", False)
93+
94+
95+
def test_set_value_backend_error(mock_backend):
96+
"""Test error handling when backend.set_value raises an exception."""
97+
mock_backend.set_value.side_effect = RuntimeError("Backend error")
98+
value = Value(path="app.replicas", environment="dev", _backend=mock_backend)
99+
100+
with pytest.raises(RuntimeError, match="Backend error"):
101+
value.set("test-value")
102+
103+
mock_backend.set_value.assert_called_once_with("app.replicas", "dev", "test-value")
104+
105+
84106
def test_to_dict(mock_backend):
85107
"""Test serializing a value."""
86108
value = Value(path="app.replicas", environment="dev", _backend=mock_backend)

0 commit comments

Comments
 (0)