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

Function TestQueryTraceWithRange

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

Source from the content-addressed store, hash-verified

77}
78
79func TestQueryTraceWithRange(t *testing.T) {
80 trace := &tempopb.Trace{}
81 t.Run("returns an error if start time is greater than end time", func(t *testing.T) {
82 client := New("www.tempo.com", "1000")
83 response, err := client.QueryTraceWithRange(context.Background(), "notfound", 3000, 2000)
84
85 assert.Error(t, err)
86 assert.Nil(t, response)
87 })
88
89 t.Run("returns a trace with range when is found", func(t *testing.T) {
90 mockTransport := MockRoundTripper(func(req *http.Request) *http.Response {
91 assert.Equal(t, "www.tempo.com/api/traces/100?end=2000&start=1000", fmt.Sprint(req.URL))
92 assert.Equal(t, "application/protobuf", req.Header.Get("Accept"))
93 response, _ := proto.Marshal(trace)
94 return &http.Response{
95 StatusCode: 200,
96 Body: io.NopCloser(bytes.NewReader(response)),
97 }
98 })
99
100 client := New("www.tempo.com", "1000")
101 client.WithTransport(mockTransport)
102 response, err := client.QueryTraceWithRange(context.Background(), "100", 1000, 2000)
103
104 assert.NoError(t, err)
105 assert.True(t, proto.Equal(trace, response))
106 })
107
108 t.Run("returns a trace with range not found error on 404", func(t *testing.T) {
109 mockTransport := MockRoundTripper(func(_ *http.Request) *http.Response {
110 return &http.Response{
111 StatusCode: 404,
112 Body: nil,
113 }
114 })
115
116 client := New("www.tempo.com", "1000")
117 client.WithTransport(mockTransport)
118 response, err := client.QueryTraceWithRange(context.Background(), "notfound", 1000, 2000)
119
120 assert.Error(t, err)
121 assert.Nil(t, response)
122 })
123}

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected