Home / File/ routes_test.go — gin Source File

routes_test.go — gin Source File

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

File go GinCore Context 1 imports 32 functions 3 classes

Entity Profile

Dependency Diagram

graph LR
  45929e18_70ca_7c55_01e0_596be99dd824["routes_test.go"]
  e8c9ceab_299a_1e0e_919f_ddb404deb199["fmt"]
  45929e18_70ca_7c55_01e0_596be99dd824 --> e8c9ceab_299a_1e0e_919f_ddb404deb199
  style 45929e18_70ca_7c55_01e0_596be99dd824 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 (
	"fmt"
	"net/http"
	"net/http/httptest"
	"os"
	"path/filepath"
	"testing"

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

type header struct {
	Key   string
	Value string
}

// PerformRequest for testing gin router.
func PerformRequest(r http.Handler, method, path string, headers ...header) *httptest.ResponseRecorder {
	req := httptest.NewRequest(method, path, nil)
	for _, h := range headers {
		req.Header.Add(h.Key, h.Value)
	}
	w := httptest.NewRecorder()
	r.ServeHTTP(w, req)
	return w
}

func testRouteOK(method string, t *testing.T) {
	passed := false
	passedAny := false
	r := New()
	r.Any("/test2", func(c *Context) {
		passedAny = true
	})
	r.Handle(method, "/test", func(c *Context) {
		passed = true
	})

	w := PerformRequest(r, method, "/test")
	assert.True(t, passed)
	assert.Equal(t, http.StatusOK, w.Code)

	PerformRequest(r, method, "/test2")
	assert.True(t, passedAny)
}

// TestSingleRouteOK tests that POST route is correctly invoked.
func testRouteNotOK(method string, t *testing.T) {
	passed := false
	router := New()
	router.Handle(method, "/test_2", func(c *Context) {
		passed = true
	})
// ... (732 more lines)

Domain

Subdomains

Types

Dependencies

  • fmt

Frequently Asked Questions

What does routes_test.go do?
routes_test.go is a source file in the gin codebase, written in go. It belongs to the GinCore domain, Context subdomain.
What functions are defined in routes_test.go?
routes_test.go defines 32 function(s): PerformRequest, TestEngineHandleMethodNotAllowedCornerCase, TestMiddlewareCalledOnceByRouterStaticFSNotFound, TestRouteContextHoldsFullPath, TestRouteNotAllowedDisabled, TestRouteNotAllowedEnabled, TestRouteNotAllowedEnabled2, TestRouteNotAllowedEnabled3, TestRouteNotOK, TestRouteNotOK2, and 22 more.
What does routes_test.go depend on?
routes_test.go imports 1 module(s): fmt.
Where is routes_test.go in the architecture?
routes_test.go is located at routes_test.go (domain: GinCore, subdomain: Context).

Analyze Your Own Codebase

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

Try Supermodel Free