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

Function TestRenderDataContentLength

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

Source from the content-addressed store, hash-verified

522}
523
524func TestRenderDataContentLength(t *testing.T) {
525 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
526 size, err := strconv.Atoi(r.URL.Query().Get("size"))
527 assert.NoError(t, err)
528
529 data := Data{
530 ContentType: "application/octet-stream",
531 Data: make([]byte, size),
532 }
533 assert.NoError(t, data.Render(w))
534 }))
535 t.Cleanup(srv.Close)
536
537 for _, size := range []int{0, 1, 100, 100_000} {
538 t.Run(strconv.Itoa(size), func(t *testing.T) {
539 resp, err := http.Get(srv.URL + "?size=" + strconv.Itoa(size))
540 require.NoError(t, err)
541 defer resp.Body.Close()
542
543 assert.Equal(t, "application/octet-stream", resp.Header.Get("Content-Type"))
544 assert.Equal(t, strconv.Itoa(size), resp.Header.Get("Content-Length"))
545
546 actual, err := io.Copy(io.Discard, resp.Body)
547 require.NoError(t, err)
548 assert.EqualValues(t, size, actual)
549 })
550 }
551}
552
553func TestRenderDataError(t *testing.T) {
554 ew := &errorWriter{

Callers

nothing calls this directly

Calls 6

RenderMethod · 0.95
QueryMethod · 0.80
RunMethod · 0.80
CloseMethod · 0.80
CopyMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected