TestContextRenderProtoBuf tests that the response is serialized as ProtoBuf and Content-Type is set to application/x-protobuf and we just use the example protobuf to check if the response is correct
(t *testing.T)
| 1513 | // and Content-Type is set to application/x-protobuf |
| 1514 | // and we just use the example protobuf to check if the response is correct |
| 1515 | func TestContextRenderProtoBuf(t *testing.T) { |
| 1516 | w := httptest.NewRecorder() |
| 1517 | c, _ := CreateTestContext(w) |
| 1518 | |
| 1519 | reps := []int64{int64(1), int64(2)} |
| 1520 | label := "test" |
| 1521 | data := &testdata.Test{ |
| 1522 | Label: &label, |
| 1523 | Reps: reps, |
| 1524 | } |
| 1525 | |
| 1526 | c.ProtoBuf(http.StatusCreated, data) |
| 1527 | |
| 1528 | protoData, err := proto.Marshal(data) |
| 1529 | require.NoError(t, err) |
| 1530 | |
| 1531 | assert.Equal(t, http.StatusCreated, w.Code) |
| 1532 | assert.Equal(t, string(protoData), w.Body.String()) |
| 1533 | assert.Equal(t, "application/x-protobuf", w.Header().Get("Content-Type")) |
| 1534 | } |
| 1535 | |
| 1536 | func TestContextHeaders(t *testing.T) { |
| 1537 | c, _ := CreateTestContext(httptest.NewRecorder()) |