Home / File/ utils_test.go — gin Source File

utils_test.go — gin Source File

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

File go GinCore Routing 1 imports 15 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  40dd6e0f_7abb_6ce7_1b7d_0ff510263efc["utils_test.go"]
  fefe783b_8987_7aed_66c9_b2860bfc32e7["bytes"]
  40dd6e0f_7abb_6ce7_1b7d_0ff510263efc --> fefe783b_8987_7aed_66c9_b2860bfc32e7
  style 40dd6e0f_7abb_6ce7_1b7d_0ff510263efc 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 gin

import (
	"bytes"
	"encoding/xml"
	"fmt"
	"math"
	"net/http"
	"testing"

	"github.com/stretchr/testify/assert"
)

func init() {
	SetMode(TestMode)
}

func BenchmarkParseAccept(b *testing.B) {
	for b.Loop() {
		parseAccept("text/html , application/xhtml+xml,application/xml;q=0.9,  */* ;q=0.8")
	}
}

type testStruct struct {
	T *testing.T
}

func (t *testStruct) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	assert.Equal(t.T, http.MethodPost, req.Method)
	assert.Equal(t.T, "/path", req.URL.Path)
	w.WriteHeader(http.StatusInternalServerError)
	fmt.Fprint(w, "hello")
}

func TestWrap(t *testing.T) {
	router := New()
	router.POST("/path", WrapH(&testStruct{t}))
	router.GET("/path2", WrapF(func(w http.ResponseWriter, req *http.Request) {
		assert.Equal(t, http.MethodGet, req.Method)
		assert.Equal(t, "/path2", req.URL.Path)
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprint(w, "hola!")
	}))

	w := PerformRequest(router, http.MethodPost, "/path")
	assert.Equal(t, http.StatusInternalServerError, w.Code)
	assert.Equal(t, "hello", w.Body.String())

	w = PerformRequest(router, http.MethodGet, "/path2")
	assert.Equal(t, http.StatusBadRequest, w.Code)
	assert.Equal(t, "hola!", w.Body.String())
}

func TestLastChar(t *testing.T) {
	assert.Equal(t, uint8('a'), lastChar("hola"))
	assert.Equal(t, uint8('s'), lastChar("adios"))
// ... (102 more lines)

Domain

Subdomains

Classes

Dependencies

  • bytes

Frequently Asked Questions

What does utils_test.go do?
utils_test.go is a source file in the gin codebase, written in go. It belongs to the GinCore domain, Routing subdomain.
What functions are defined in utils_test.go?
utils_test.go defines 15 function(s): BenchmarkParseAccept, TestBindMiddleware, TestChooseData, TestFilterFlags, TestFunctionName, TestIsASCII, TestJoinPaths, TestLastChar, TestMarshalXMLforH, TestParseAccept, and 5 more.
What does utils_test.go depend on?
utils_test.go imports 1 module(s): bytes.
Where is utils_test.go in the architecture?
utils_test.go is located at utils_test.go (domain: GinCore, subdomain: Routing).

Analyze Your Own Codebase

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

Try Supermodel Free