MCPcopy
hub / github.com/grafana/tempo / TestApplyHeadersHTTP

Function TestApplyHeadersHTTP

cmd/tempo-cli/shared_test.go:13–76  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestApplyHeadersHTTP(t *testing.T) {
14 tests := []struct {
15 name string
16 headers []string
17 expectedHeaders map[string]string
18 }{
19 {
20 name: "single header",
21 headers: []string{"X-TOKEN=my-secret"},
22 expectedHeaders: map[string]string{
23 "X-Token": "my-secret",
24 },
25 },
26 {
27 name: "multiple headers",
28 headers: []string{"X-TOKEN=my-secret", "X-Custom=value"},
29 expectedHeaders: map[string]string{
30 "X-Token": "my-secret",
31 "X-Custom": "value",
32 },
33 },
34 {
35 name: "malformed header without equals is ignored",
36 headers: []string{"no-equals-sign"},
37 expectedHeaders: map[string]string{},
38 },
39 {
40 name: "value containing equals",
41 headers: []string{"Authorization=Bearer token=abc"},
42 expectedHeaders: map[string]string{
43 "Authorization": "Bearer token=abc",
44 },
45 },
46 {
47 name: "empty input",
48 headers: []string{},
49 expectedHeaders: map[string]string{},
50 },
51 {
52 name: "empty key is ignored",
53 headers: []string{"=value"},
54 expectedHeaders: map[string]string{},
55 },
56 {
57 name: "whitespace around key is trimmed",
58 headers: []string{" X-TOKEN =my-secret"},
59 expectedHeaders: map[string]string{
60 "X-Token": "my-secret",
61 },
62 },
63 }
64
65 for _, tt := range tests {
66 t.Run(tt.name, func(t *testing.T) {
67 req, _ := http.NewRequest("GET", "http://localhost:3200/api/search", nil)
68 applyHeadersHTTP(req, tt.headers)
69
70 require.Len(t, req.Header, len(tt.expectedHeaders))

Callers

nothing calls this directly

Calls 5

applyHeadersHTTPFunction · 0.85
LenMethod · 0.65
GetMethod · 0.65
RunMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected