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

Function toHTTPResponseWithFormat

modules/frontend/combiner/common_test.go:290–316  ·  view source on GitHub ↗

Helper functions for creating test responses with different marshaling formats

(t *testing.T, pb proto.Message, statusCode int, responseData any, format api.MarshallingFormat)

Source from the content-addressed store, hash-verified

288
289// Helper functions for creating test responses with different marshaling formats
290func toHTTPResponseWithFormat(t *testing.T, pb proto.Message, statusCode int, responseData any, format api.MarshallingFormat) PipelineResponse {
291 var body []byte
292 var err error
293
294 if pb != nil {
295 if format == api.MarshallingFormatProtobuf {
296 body, err = proto.Marshal(pb)
297 require.NoError(t, err)
298 } else {
299 m := jsonpb.Marshaler{}
300 bodyStr, marshalErr := m.MarshalToString(pb)
301 require.NoError(t, marshalErr)
302 body = []byte(bodyStr)
303 }
304 }
305
306 return &testPipelineResponse{
307 responseData: responseData,
308 r: &http.Response{
309 Body: io.NopCloser(strings.NewReader(string(body))),
310 StatusCode: statusCode,
311 Header: http.Header{
312 api.HeaderContentType: {string(format)},
313 },
314 },
315 }
316}
317
318func toHTTPResponse(t *testing.T, pb proto.Message, statusCode int) PipelineResponse {
319 return toHTTPResponseWithFormat(t, pb, statusCode, nil, api.HeaderAcceptJSON)

Calls 1

MarshalMethod · 0.65

Tested by

no test coverage detected