MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestRequestIdFromHeaderIsUsed

Function TestRequestIdFromHeaderIsUsed

pkg/api/middlewares_test.go:94–115  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

92}
93
94func TestRequestIdFromHeaderIsUsed(t *testing.T) {
95 const providedID = "my-test-id-123"
96
97 middleware := HTTPHeaderMiddleware{
98 RequestIdHeader: "X-Request-ID",
99 }
100
101 h := http.Header{}
102 h.Add("X-Request-ID", providedID)
103
104 req := &http.Request{
105 Method: "GET",
106 RequestURI: "/test",
107 Body: http.NoBody,
108 Header: h,
109 }
110 req = req.WithContext(context.Background())
111 req = middleware.injectRequestContext(req)
112
113 requestID := requestmeta.RequestIdFromContext(req.Context())
114 require.Equal(t, providedID, requestID, "Request ID from header should be used")
115}
116
117func TestTargetHeaderAndRequestIdHeaderOverlap(t *testing.T) {
118 const headerKey = "X-Request-ID"

Callers

nothing calls this directly

Calls 5

injectRequestContextMethod · 0.95
RequestIdFromContextFunction · 0.92
EqualMethod · 0.65
AddMethod · 0.45
ContextMethod · 0.45

Tested by

no test coverage detected