Skip to content

Commit 8db8cab

Browse files
committed
tests(traceutils): cover all supported header formats
Signed-off-by: Varsha GS <[email protected]>
1 parent 24370ac commit 8db8cab

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

tests/util/test_traceutils.py

+44-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# (c) Copyright IBM Corp. 2024
22

3-
from unittest.mock import patch
3+
import pytest
44

55
from instana.singletons import agent, tracer
66
from instana.tracer import InstanaTracer
@@ -12,26 +12,61 @@
1212
)
1313

1414

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:
1653
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)
2255
assert len(span.attributes) == 2
2356
assert span.attributes["http.header.X-Capture-This-Too"] == "this too"
2457
assert span.attributes["http.header.X-Capture-That-Too"] == "that too"
2558

2659

27-
def test_get_activate_tracer() -> None:
60+
def test_get_activate_tracer(mocker) -> None:
2861
assert not get_active_tracer()
2962

3063
with tracer.start_as_current_span("test"):
3164
response = get_active_tracer()
3265
assert isinstance(response, InstanaTracer)
3366
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+
):
3570
assert not get_active_tracer()
3671

3772

0 commit comments

Comments
 (0)