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

Function TestRenderProtoBuf

render/render_test.go:367–386  ·  view source on GitHub ↗

test Protobuf rendering

(t *testing.T)

Source from the content-addressed store, hash-verified

365
366// test Protobuf rendering
367func TestRenderProtoBuf(t *testing.T) {
368 w := httptest.NewRecorder()
369 reps := []int64{int64(1), int64(2)}
370 label := "test"
371 data := &testdata.Test{
372 Label: &label,
373 Reps: reps,
374 }
375
376 (ProtoBuf{data}).WriteContentType(w)
377 protoData, err := proto.Marshal(data)
378 require.NoError(t, err)
379 assert.Equal(t, "application/x-protobuf", w.Header().Get("Content-Type"))
380
381 err = (ProtoBuf{data}).Render(w)
382
383 require.NoError(t, err)
384 assert.Equal(t, string(protoData), w.Body.String())
385 assert.Equal(t, "application/x-protobuf", w.Header().Get("Content-Type"))
386}
387
388func TestRenderProtoBufFail(t *testing.T) {
389 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 6

WriteContentTypeMethod · 0.65
MarshalMethod · 0.65
RenderMethod · 0.65
StringMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected