@@ -53,6 +53,29 @@ def test_connection_info(self) -> None:
5353 config = CloudEventsConfig (endpoint = "https://example.com/webhook" )
5454 assert "POST https://example.com/webhook" in config .get_connection_info ()
5555
56+ @patch .dict (
57+ os .environ ,
58+ {"K_CE_OVERRIDES" : '{"extensions": {"extra": "test", "num": 42}}' },
59+ )
60+ def test_k_ce_overrides_valid (self ) -> None :
61+ """Test K_CE_OVERRIDES with valid extensions."""
62+ config = CloudEventsConfig ()
63+ assert config .overrides == {"extra" : "test" , "num" : 42 }
64+
65+ @patch .dict (os .environ , {"K_CE_OVERRIDES" : '{"other": "field"}' })
66+ def test_k_ce_overrides_no_extensions (self ) -> None :
67+ """Test K_CE_OVERRIDES without extensions field."""
68+ config = CloudEventsConfig ()
69+ assert config .overrides == {}
70+
71+ @patch .dict (os .environ , {"K_CE_OVERRIDES" : "invalid-json" })
72+ def test_k_ce_overrides_invalid_json (self ) -> None :
73+ """Test K_CE_OVERRIDES with invalid JSON."""
74+ from pydantic import ValidationError
75+
76+ with pytest .raises (ValidationError ):
77+ CloudEventsConfig ()
78+
5679
5780class TestCloudEventsAdapter :
5881 """Test CloudEvents output adapter."""
@@ -229,3 +252,52 @@ async def test_health_check(self, adapter: CloudEventsAdapter) -> None:
229252 # Running with client
230253 adapter ._client = MagicMock ()
231254 assert await adapter .health_check () is True
255+
256+ @patch .dict (
257+ os .environ ,
258+ {
259+ "K_CE_OVERRIDES" : (
260+ '{"extensions": {"extra": "test-value", "priority": "high"}}'
261+ )
262+ },
263+ )
264+ def test_convert_to_cloudevent_with_overrides (
265+ self , adapter : CloudEventsAdapter , sample_event : NotificationEvent
266+ ) -> None :
267+ """Test CloudEvent conversion with K_CE_OVERRIDES."""
268+ cloud_event = adapter ._convert_to_cloudevent (sample_event )
269+
270+ assert isinstance (cloud_event , CloudEvent )
271+ assert cloud_event ["extra" ] == "test-value"
272+ assert cloud_event ["priority" ] == "high"
273+
274+ @patch .dict (os .environ , {"K_CE_OVERRIDES" : '{"extensions": {"number": 123}}' })
275+ def test_convert_to_cloudevent_with_number_override (
276+ self , adapter : CloudEventsAdapter , sample_event : NotificationEvent
277+ ) -> None :
278+ """Test CloudEvent conversion with number in K_CE_OVERRIDES."""
279+ cloud_event = adapter ._convert_to_cloudevent (sample_event )
280+
281+ assert cloud_event ["number" ] == "123" # Should be converted to string
282+
283+ @patch .dict (os .environ , {"K_CE_OVERRIDES" : "invalid-json" })
284+ def test_convert_to_cloudevent_invalid_overrides (
285+ self , adapter : CloudEventsAdapter , sample_event : NotificationEvent
286+ ) -> None :
287+ """Test CloudEvent conversion with invalid K_CE_OVERRIDES JSON."""
288+ cloud_event = adapter ._convert_to_cloudevent (sample_event )
289+
290+ # Should work normally without overrides
291+ assert isinstance (cloud_event , CloudEvent )
292+ assert cloud_event ["source" ] == "/eoapi/stac"
293+
294+ @patch .dict (os .environ , {"K_CE_OVERRIDES" : '{"other": "field"}' })
295+ def test_convert_to_cloudevent_no_extensions (
296+ self , adapter : CloudEventsAdapter , sample_event : NotificationEvent
297+ ) -> None :
298+ """Test CloudEvent conversion with K_CE_OVERRIDES but no extensions field."""
299+ cloud_event = adapter ._convert_to_cloudevent (sample_event )
300+
301+ # Should work normally without extensions
302+ assert isinstance (cloud_event , CloudEvent )
303+ assert cloud_event ["source" ] == "/eoapi/stac"
0 commit comments