Home / File/ recovery_test.go — gin Source File

recovery_test.go — gin Source File

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

File go GinCore Middleware 1 imports 12 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  c9a553a7_05a4_91a7_23b0_924f9f59d021["recovery_test.go"]
  a5b376ce_f9b0_6a3f_779b_0a46ea5ed1b7["net"]
  c9a553a7_05a4_91a7_23b0_924f9f59d021 --> a5b376ce_f9b0_6a3f_779b_0a46ea5ed1b7
  style c9a553a7_05a4_91a7_23b0_924f9f59d021 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 (
	"net"
	"net/http"
	"os"
	"strings"
	"syscall"
	"testing"

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

func TestPanicClean(t *testing.T) {
	buffer := new(strings.Builder)
	router := New()
	password := "my-super-secret-password"
	router.Use(RecoveryWithWriter(buffer))
	router.GET("/recovery", func(c *Context) {
		c.AbortWithStatus(http.StatusBadRequest)
		panic("Oupps, Houston, we have a problem")
	})
	// RUN
	w := PerformRequest(router, http.MethodGet, "/recovery",
		header{
			Key:   "Host",
			Value: "www.google.com",
		},
		header{
			Key:   "Authorization",
			Value: "Bearer " + password,
		},
		header{
			Key:   "Content-Type",
			Value: "application/json",
		},
	)
	// TEST
	assert.Equal(t, http.StatusBadRequest, w.Code)

	// Check the buffer does not have the secret key
	assert.NotContains(t, buffer.String(), password)
}

// TestPanicInHandler assert that panic has been recovered.
func TestPanicInHandler(t *testing.T) {
	buffer := new(strings.Builder)
	router := New()
	router.Use(RecoveryWithWriter(buffer))
	router.GET("/recovery", func(_ *Context) {
		panic("Oupps, Houston, we have a problem")
	})
	// RUN
	w := PerformRequest(router, http.MethodGet, "/recovery")
	// TEST
	assert.Equal(t, http.StatusInternalServerError, w.Code)
// ... (310 more lines)

Domain

Subdomains

Classes

Types

Dependencies

  • net

Frequently Asked Questions

What does recovery_test.go do?
recovery_test.go is a source file in the gin codebase, written in go. It belongs to the GinCore domain, Middleware subdomain.
What functions are defined in recovery_test.go?
recovery_test.go defines 12 function(s): BenchmarkStack, TestCustomRecovery, TestCustomRecoveryWithWriter, TestFunction, TestPanicClean, TestPanicInHandler, TestPanicWithAbort, TestPanicWithAbortHandler, TestPanicWithBrokenPipe, TestReadNthLine, and 2 more.
What does recovery_test.go depend on?
recovery_test.go imports 1 module(s): net.
Where is recovery_test.go in the architecture?
recovery_test.go is located at recovery_test.go (domain: GinCore, subdomain: Middleware).

Analyze Your Own Codebase

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

Try Supermodel Free