| 1678 | } |
| 1679 | |
| 1680 | func TestContextNegotiationWithPROTOBUF(t *testing.T) { |
| 1681 | w := httptest.NewRecorder() |
| 1682 | c, _ := CreateTestContext(w) |
| 1683 | c.Request = httptest.NewRequest(http.MethodPost, "/", nil) |
| 1684 | |
| 1685 | reps := []int64{int64(1), int64(2)} |
| 1686 | label := "test" |
| 1687 | data := &testdata.Test{ |
| 1688 | Label: &label, |
| 1689 | Reps: reps, |
| 1690 | } |
| 1691 | |
| 1692 | c.Negotiate(http.StatusCreated, Negotiate{ |
| 1693 | Offered: []string{MIMEPROTOBUF, MIMEJSON, MIMEXML}, |
| 1694 | Data: data, |
| 1695 | }) |
| 1696 | |
| 1697 | // Marshal original data for comparison |
| 1698 | protoData, err := proto.Marshal(data) |
| 1699 | require.NoError(t, err) |
| 1700 | |
| 1701 | assert.Equal(t, http.StatusCreated, w.Code) |
| 1702 | assert.Equal(t, string(protoData), w.Body.String()) |
| 1703 | assert.Equal(t, "application/x-protobuf", w.Header().Get("Content-Type")) |
| 1704 | } |
| 1705 | |
| 1706 | func TestContextNegotiationWithBSON(t *testing.T) { |
| 1707 | w := httptest.NewRecorder() |