MCPcopy
hub / github.com/gin-gonic/gin / TestContextNegotiationWithPROTOBUF

Function TestContextNegotiationWithPROTOBUF

context_test.go:1680–1704  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1678}
1679
1680func 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
1706func TestContextNegotiationWithBSON(t *testing.T) {
1707 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 6

CreateTestContextFunction · 0.85
NegotiateMethod · 0.80
MarshalMethod · 0.65
StringMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected