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

Function TestQueryTrace

pkg/httpclient/client_test.go:22–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20}
21
22func TestQueryTrace(t *testing.T) {
23 trace := &tempopb.Trace{}
24 t.Run("returns a trace when is found", func(t *testing.T) {
25 mockTransport := MockRoundTripper(func(req *http.Request) *http.Response {
26 assert.Equal(t, "www.tempo.com/api/traces/100", req.URL.Path)
27 assert.Equal(t, "application/protobuf", req.Header.Get("Accept"))
28 response, _ := proto.Marshal(trace)
29 return &http.Response{
30 StatusCode: 200,
31 Body: io.NopCloser(bytes.NewReader(response)),
32 }
33 })
34
35 client := New("www.tempo.com", "1000")
36 client.WithTransport(mockTransport)
37 response, err := client.QueryTrace("100")
38
39 assert.NoError(t, err)
40 assert.True(t, proto.Equal(trace, response))
41 })
42
43 t.Run("includes the recentDataTarget header", func(t *testing.T) {
44 mockTransport := MockRoundTripper(func(req *http.Request) *http.Response {
45 assert.Equal(t, liveStoreHeaderValue, req.Header.Get(recentDataTargetHeader))
46 response, _ := proto.Marshal(trace)
47 return &http.Response{
48 StatusCode: 200,
49 Body: io.NopCloser(bytes.NewReader(response)),
50 }
51 })
52
53 client := New("www.tempo.com", "1000")
54 client.QueryLiveStores = true
55 client.WithTransport(mockTransport)
56 response, err := client.QueryTrace("100")
57
58 assert.NoError(t, err)
59 assert.True(t, proto.Equal(trace, response))
60 })
61
62 t.Run("returns a trace not found error on 404", func(t *testing.T) {
63 mockTransport := MockRoundTripper(func(_ *http.Request) *http.Response {
64 return &http.Response{
65 StatusCode: 404,
66 Body: nil,
67 }
68 })
69
70 client := New("www.tempo.com", "1000")
71 client.WithTransport(mockTransport)
72 response, err := client.QueryTrace("notfound")
73
74 assert.Error(t, err)
75 assert.Nil(t, response)
76 })
77}
78
79func TestQueryTraceWithRange(t *testing.T) {

Callers

nothing calls this directly

Calls 9

MockRoundTripperFuncType · 0.85
NewFunction · 0.70
GetMethod · 0.65
MarshalMethod · 0.65
WithTransportMethod · 0.65
QueryTraceMethod · 0.65
ErrorMethod · 0.65
RunMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected