|
1 | 1 | # (c) Copyright IBM Corp. 2024
|
2 | 2 |
|
3 |
| -from unittest.mock import patch |
| 3 | +import pytest |
4 | 4 |
|
5 | 5 | from instana.singletons import agent, tracer
|
6 | 6 | from instana.tracer import InstanaTracer
|
|
12 | 12 | )
|
13 | 13 |
|
14 | 14 |
|
15 |
| -def test_extract_custom_headers(span) -> None: |
| 15 | +@pytest.mark.parametrize( |
| 16 | + "custom_headers, format", |
| 17 | + [ |
| 18 | + ( |
| 19 | + { |
| 20 | + "X-Capture-This-Too": "this too", |
| 21 | + "X-Capture-That-Too": "that too", |
| 22 | + }, |
| 23 | + False, |
| 24 | + ), |
| 25 | + ( |
| 26 | + { |
| 27 | + "HTTP_X_CAPTURE_THIS_TOO": "this too", |
| 28 | + "HTTP_X_CAPTURE_THAT_TOO": "that too", |
| 29 | + }, |
| 30 | + True, |
| 31 | + ), |
| 32 | + ( |
| 33 | + [("X-CAPTURE-THIS-TOO", "this too"), ("x-capture-that-too", "that too")], |
| 34 | + False, |
| 35 | + ), |
| 36 | + ( |
| 37 | + [ |
| 38 | + (b"X-Capture-This-Too", b"this too"), |
| 39 | + (b"X-Capture-That-Too", b"that too"), |
| 40 | + ], |
| 41 | + False, |
| 42 | + ), |
| 43 | + ( |
| 44 | + [ |
| 45 | + ("HTTP_X_CAPTURE_THIS_TOO", "this too"), |
| 46 | + ("HTTP_X_CAPTURE_THAT_TOO", "that too"), |
| 47 | + ], |
| 48 | + True, |
| 49 | + ), |
| 50 | + ], |
| 51 | +) |
| 52 | +def test_extract_custom_headers(span, custom_headers, format) -> None: |
16 | 53 | agent.options.extra_http_headers = ["X-Capture-This-Too", "X-Capture-That-Too"]
|
17 |
| - request_headers = { |
18 |
| - "X-Capture-This-Too": "this too", |
19 |
| - "X-Capture-That-Too": "that too", |
20 |
| - } |
21 |
| - extract_custom_headers(span, request_headers) |
| 54 | + extract_custom_headers(span, custom_headers, format=format) |
22 | 55 | assert len(span.attributes) == 2
|
23 | 56 | assert span.attributes["http.header.X-Capture-This-Too"] == "this too"
|
24 | 57 | assert span.attributes["http.header.X-Capture-That-Too"] == "that too"
|
25 | 58 |
|
26 | 59 |
|
27 |
| -def test_get_activate_tracer() -> None: |
| 60 | +def test_get_activate_tracer(mocker) -> None: |
28 | 61 | assert not get_active_tracer()
|
29 | 62 |
|
30 | 63 | with tracer.start_as_current_span("test"):
|
31 | 64 | response = get_active_tracer()
|
32 | 65 | assert isinstance(response, InstanaTracer)
|
33 | 66 | assert response == tracer
|
34 |
| - with patch("instana.span.span.InstanaSpan.is_recording", return_value=False): |
| 67 | + with mocker.patch( |
| 68 | + "instana.span.span.InstanaSpan.is_recording", return_value=False |
| 69 | + ): |
35 | 70 | assert not get_active_tracer()
|
36 | 71 |
|
37 | 72 |
|
|
0 commit comments