Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixing and adding unit tests
  • Loading branch information
mhlidd committed Jul 1, 2025
commit c56858fb956da3748e5e3936700e59096938e823
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import static datadog.trace.api.gateway.Events.EVENTS
class HttpServerDecoratorTest extends ServerDecoratorTest {

def span = Mock(AgentSpan)
def respHeaders = ['X-Custom-Header': 'custom-value', 'Content-Type': 'application/json']

boolean origAppSecActive

Expand Down Expand Up @@ -353,26 +354,33 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {

def "test response headers with trace.header.tags"() {
setup:
injectSysConfig("trace.header.tags", headerTags)
def traceConfig = Mock(TraceConfig)
traceConfig.getResponseHeaderTags() >> [(headerTags.split(":")[0].toLowerCase()): headerTags.split(":")[1]]

traceConfig.getResponseHeaderTags() >> headerTags

def tags = [:]

def responseSpan = Mock(AgentSpan)
responseSpan.traceConfig() >> traceConfig

responseSpan.setTag(_, _) >> { String k, String v ->
tags[k] = v
return responseSpan
}

def decorator = newDecorator()

when:
decorator.onResponse(responseSpan, resp)

then:
for (Map.Entry<String, String> entry : expectedTag.entrySet()) {
responseSpan.getTag(entry.getKey()).equals(entry.getValue())
assert tags[entry.getKey()] == entry.getValue()
}

where:
headerTags | resp | expectedTag
"X-Custom-Header:abc" | [status: 200, headers: ['X-Custom-Header': 'custom-value', 'Content-Type': 'application/json']] | [abc:"custom-value"]
headerTags | resp | expectedTag
[:] | [status: 200, headers: ['X-Custom-Header': 'custom-value', 'Content-Type': 'application/json']] | [:]
Comment thread
mhlidd marked this conversation as resolved.
["x-custom-header": "abc"] | [status: 200, headers: ['X-Custom-Header': 'custom-value', 'Content-Type': 'application/json']] | [abc:"custom-value"]
["*": "datadog.response.headers."] | [status: 200, headers: ['X-Custom-Header': 'custom-value', 'Content-Type': 'application/json']] | ["datadog.response.headers.x-custom-header":"custom-value", "datadog.response.headers.content-type":"application/json"]
}

@Override
Expand Down