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

Function TestRequestIdInjection

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

Source from the content-addressed store, hash-verified

74}
75
76func TestRequestIdInjection(t *testing.T) {
77 middleware := HTTPHeaderMiddleware{
78 RequestIdHeader: "X-Request-ID",
79 }
80
81 req := &http.Request{
82 Method: "GET",
83 RequestURI: "/test",
84 Body: http.NoBody,
85 Header: http.Header{},
86 }
87 req = req.WithContext(context.Background())
88 req = middleware.injectRequestContext(req)
89
90 requestID := requestmeta.RequestIdFromContext(req.Context())
91 require.NotEmpty(t, requestID, "Request ID should be generated if not provided")
92}
93
94func TestRequestIdFromHeaderIsUsed(t *testing.T) {
95 const providedID = "my-test-id-123"

Callers

nothing calls this directly

Calls 3

injectRequestContextMethod · 0.95
RequestIdFromContextFunction · 0.92
ContextMethod · 0.45

Tested by

no test coverage detected