Home / File/ render_test.go — gin Source File

render_test.go — gin Source File

Architecture documentation for render_test.go, a go file in the gin codebase. 1 imports, 0 dependents.

File go ResponseRendering TemplateEngine 1 imports 34 functions

Entity Profile

Dependency Diagram

graph LR
  067a4839_481a_7bd8_fc59_5c8c3313879c["render_test.go"]
  50f09d07_ac8c_822a_71ca_5e6dc38887ef["xml"]
  067a4839_481a_7bd8_fc59_5c8c3313879c --> 50f09d07_ac8c_822a_71ca_5e6dc38887ef
  style 067a4839_481a_7bd8_fc59_5c8c3313879c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package render

import (
	"encoding/xml"
	"errors"
	"html/template"
	"net"
	"net/http"
	"net/http/httptest"
	"strconv"
	"strings"
	"testing"

	"github.com/gin-gonic/gin/codec/json"
	testdata "github.com/gin-gonic/gin/testdata/protoexample"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"go.mongodb.org/mongo-driver/bson"
	"google.golang.org/protobuf/proto"
)

// TODO unit tests
// test errors

func TestRenderJSON(t *testing.T) {
	w := httptest.NewRecorder()
	data := map[string]any{
		"foo":  "bar",
		"html": "<b>",
	}

	(JSON{data}).WriteContentType(w)
	assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))

	err := (JSON{data}).Render(w)

	require.NoError(t, err)
	assert.JSONEq(t, "{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}", w.Body.String())
	assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
}

func TestRenderJSONError(t *testing.T) {
	w := httptest.NewRecorder()
	data := make(chan int)

	// json: unsupported type: chan int
	require.Error(t, (JSON{data}).Render(w))
}

func TestRenderIndentedJSON(t *testing.T) {
	w := httptest.NewRecorder()
	data := map[string]any{
		"foo": "bar",
		"bar": "foo",
	}

// ... (595 more lines)

Subdomains

Dependencies

  • xml

Frequently Asked Questions

What does render_test.go do?
render_test.go is a source file in the gin codebase, written in go. It belongs to the ResponseRendering domain, TemplateEngine subdomain.
What functions are defined in render_test.go?
render_test.go defines 34 function(s): TestRenderAsciiJSON, TestRenderAsciiJSONFail, TestRenderBSON, TestRenderData, TestRenderHTMLDebugFS, TestRenderHTMLDebugFiles, TestRenderHTMLDebugGlob, TestRenderHTMLDebugPanics, TestRenderHTMLTemplate, TestRenderHTMLTemplateEmptyName, and 24 more.
What does render_test.go depend on?
render_test.go imports 1 module(s): xml.
Where is render_test.go in the architecture?
render_test.go is located at render/render_test.go (domain: ResponseRendering, subdomain: TemplateEngine, directory: render).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free