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

Function TestContextRenderProtoBuf

context_test.go:1515–1534  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
1515func 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
1536func TestContextHeaders(t *testing.T) {
1537 c, _ := CreateTestContext(httptest.NewRecorder())

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected