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

Function TestRenderBSON

render/render_test.go:395–418  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

393}
394
395func TestRenderBSON(t *testing.T) {
396 w := httptest.NewRecorder()
397 reps := []int64{int64(1), int64(2)}
398 type mystruct struct {
399 Label string
400 Reps []int64
401 }
402
403 data := &mystruct{
404 Label: "test",
405 Reps: reps,
406 }
407
408 (BSON{data}).WriteContentType(w)
409 bsonData, err := bson.Marshal(data)
410 require.NoError(t, err)
411 assert.Equal(t, "application/bson", w.Header().Get("Content-Type"))
412
413 err = (BSON{data}).Render(w)
414
415 require.NoError(t, err)
416 assert.Equal(t, bsonData, w.Body.Bytes())
417 assert.Equal(t, "application/bson", w.Header().Get("Content-Type"))
418}
419
420func TestRenderBSONError(t *testing.T) {
421 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected