TestCustomRecovery() — gin Function Reference
Architecture documentation for the TestCustomRecovery() function in recovery_test.go from the gin codebase.
Entity Profile
Dependency Diagram
graph TD 94170005_406e_1077_eb34_d0b268d5168e["TestCustomRecovery()"] c9a553a7_05a4_91a7_23b0_924f9f59d021["recovery_test.go"] 94170005_406e_1077_eb34_d0b268d5168e -->|defined in| c9a553a7_05a4_91a7_23b0_924f9f59d021 style 94170005_406e_1077_eb34_d0b268d5168e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
recovery_test.go lines 189–222
func TestCustomRecovery(t *testing.T) {
errBuffer := new(strings.Builder)
buffer := new(strings.Builder)
router := New()
DefaultErrorWriter = buffer
handleRecovery := func(c *Context, err any) {
errBuffer.WriteString(err.(string))
c.AbortWithStatus(http.StatusBadRequest)
}
router.Use(CustomRecovery(handleRecovery))
router.GET("/recovery", func(_ *Context) {
panic("Oupps, Houston, we have a problem")
})
// RUN
w := PerformRequest(router, http.MethodGet, "/recovery")
// TEST
assert.Equal(t, http.StatusBadRequest, w.Code)
assert.Contains(t, buffer.String(), "panic recovered")
assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem")
assert.Contains(t, buffer.String(), t.Name())
assert.NotContains(t, buffer.String(), "GET /recovery")
// Debug mode prints the request
SetMode(DebugMode)
// RUN
w = PerformRequest(router, http.MethodGet, "/recovery")
// TEST
assert.Equal(t, http.StatusBadRequest, w.Code)
assert.Contains(t, buffer.String(), "GET /recovery")
assert.Equal(t, strings.Repeat("Oupps, Houston, we have a problem", 2), errBuffer.String())
SetMode(TestMode)
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does TestCustomRecovery() do?
TestCustomRecovery() is a function in the gin codebase, defined in recovery_test.go.
Where is TestCustomRecovery() defined?
TestCustomRecovery() is defined in recovery_test.go at line 189.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free