Helper functions for creating test responses with different marshaling formats
(t *testing.T, pb proto.Message, statusCode int, responseData any, format api.MarshallingFormat)
| 288 | |
| 289 | // Helper functions for creating test responses with different marshaling formats |
| 290 | func 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 | |
| 318 | func toHTTPResponse(t *testing.T, pb proto.Message, statusCode int) PipelineResponse { |
| 319 | return toHTTPResponseWithFormat(t, pb, statusCode, nil, api.HeaderAcceptJSON) |
no test coverage detected