|
| 1 | +import datetime |
| 2 | + |
1 | 3 | import pytest
|
2 | 4 |
|
3 | 5 | from lumigo_tracer.auto_tag import auto_tag_event
|
@@ -299,13 +301,43 @@ def test_configuration_handler_is_supported(config, event, expected):
|
299 | 301 | assert ConfigurationHandler.is_supported(event) == expected
|
300 | 302 |
|
301 | 303 |
|
302 |
| -def test_configuration_handler_auto_tag(): |
303 |
| - Configuration.auto_tag = ["key1", "key2", "key3"] |
304 |
| - ConfigurationHandler.auto_tag({"key1": "value1", "key2": "value2", "other": "other"}) |
| 304 | +@pytest.mark.parametrize( |
| 305 | + "auto_tag_keys, event, result_tags", |
| 306 | + [ |
| 307 | + ( # happy flow non-nested |
| 308 | + ["key1", "key2", "key3"], |
| 309 | + {"key1": "value1", "key2": "value2", "other": "other"}, |
| 310 | + [{"key": "key1", "value": "value1"}, {"key": "key2", "value": "value2"}], |
| 311 | + ), |
| 312 | + (["key1.key2"], {"key1": "value1"}, []), # not exists inner key |
| 313 | + (["key1.key2"], {"other": "other"}, []), # not exists outer key |
| 314 | + ( # happy flow nested |
| 315 | + ["key1.key2"], |
| 316 | + {"key1": {"key2": "value"}, "key3": "other"}, |
| 317 | + [{"key": "key1.key2", "value": "value"}], |
| 318 | + ), |
| 319 | + ( # happy flow nested multiple keys |
| 320 | + ["key1.key2", "key3.key4"], |
| 321 | + {"key1": {"key2": "value"}, "key3": {"key4": "value2"}, "key5": "other"}, |
| 322 | + [{"key": "key1.key2", "value": "value"}, {"key": "key3.key4", "value": "value2"}], |
| 323 | + ), |
| 324 | + ], |
| 325 | +) |
| 326 | +def test_configuration_handler_auto_tag(auto_tag_keys, event, result_tags): |
| 327 | + Configuration.auto_tag = auto_tag_keys |
| 328 | + ConfigurationHandler.auto_tag(event) |
| 329 | + tags = SpansContainer.get_span().function_span[EXECUTION_TAGS_KEY] |
| 330 | + assert len(tags) == len(result_tags) |
| 331 | + for tag in result_tags: |
| 332 | + assert tag in tags |
| 333 | + |
| 334 | + |
| 335 | +def test_configuration_handler_auto_tag_failure(capsys): |
| 336 | + Configuration.auto_tag = [None, "key2"] |
| 337 | + ConfigurationHandler.auto_tag({"key1": datetime, "key2": "value"}) |
305 | 338 | tags = SpansContainer.get_span().function_span[EXECUTION_TAGS_KEY]
|
306 |
| - assert len(tags) == 2 |
307 |
| - assert {"key": "key1", "value": "value1"} in tags |
308 |
| - assert {"key": "key2", "value": "value2"} in tags |
| 339 | + assert tags == [{"key": "key2", "value": "value"}] |
| 340 | + assert "Failed to auto tag" in capsys.readouterr().out |
309 | 341 |
|
310 | 342 |
|
311 | 343 | @pytest.mark.parametrize(
|
|
0 commit comments