|
| 1 | +import pytest |
| 2 | + |
1 | 3 | from lumigo_tracer.auto_tag import auto_tag_event
|
2 |
| -from lumigo_tracer.auto_tag.auto_tag_event import EventAutoTagHandler, AutoTagEvent |
| 4 | +from lumigo_tracer.auto_tag.auto_tag_event import ( |
| 5 | + EventAutoTagHandler, |
| 6 | + AutoTagEvent, |
| 7 | + ConfigurationHandler, |
| 8 | +) |
3 | 9 | from lumigo_tracer.spans_container import SpansContainer
|
4 |
| -from lumigo_tracer.lumigo_utils import EXECUTION_TAGS_KEY |
| 10 | +from lumigo_tracer.lumigo_utils import EXECUTION_TAGS_KEY, Configuration |
5 | 11 |
|
6 | 12 |
|
7 | 13 | class ExceptionHandler(EventAutoTagHandler):
|
@@ -278,3 +284,41 @@ def test_auto_tag_key_in_header(monkeypatch):
|
278 | 284 |
|
279 | 285 | def set_header_key(monkeypatch, header: str):
|
280 | 286 | monkeypatch.setattr(auto_tag_event, "AUTO_TAG_API_GW_HEADERS", [header])
|
| 287 | + |
| 288 | + |
| 289 | +@pytest.mark.parametrize( |
| 290 | + "config, event, expected", |
| 291 | + [ |
| 292 | + (["key1"], {"key1": "value1"}, True), |
| 293 | + (["key1"], {"key2": "value2"}, False), |
| 294 | + ([], {}, False), |
| 295 | + ], |
| 296 | +) |
| 297 | +def test_configuration_handler_is_supported(config, event, expected): |
| 298 | + Configuration.auto_tag = config |
| 299 | + assert ConfigurationHandler.is_supported(event) == expected |
| 300 | + |
| 301 | + |
| 302 | +def test_configuration_handler_auto_tag(): |
| 303 | + Configuration.auto_tag = ["key1", "key2", "key3"] |
| 304 | + ConfigurationHandler.auto_tag({"key1": "value1", "key2": "value2", "other": "other"}) |
| 305 | + 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 |
| 309 | + |
| 310 | + |
| 311 | +@pytest.mark.parametrize( |
| 312 | + "value, expected", |
| 313 | + [ |
| 314 | + (1, "1"), # int |
| 315 | + ({"a": "b"}, "{'a': 'b'}"), # dict |
| 316 | + ], |
| 317 | +) |
| 318 | +def test_configuration_handler_auto_tag_non_string(value, expected): |
| 319 | + Configuration.auto_tag = ["key1"] |
| 320 | + |
| 321 | + ConfigurationHandler.auto_tag({"key1": value}) |
| 322 | + |
| 323 | + tags = SpansContainer.get_span().function_span[EXECUTION_TAGS_KEY] |
| 324 | + assert {"key": "key1", "value": expected} in tags |
0 commit comments