Home / Function/ TestPanicWithAbortHandler() — gin Function Reference

TestPanicWithAbortHandler() — gin Function Reference

Architecture documentation for the TestPanicWithAbortHandler() function in recovery_test.go from the gin codebase.

Entity Profile

Relationship Graph

Source Code

recovery_test.go lines 132–153

func TestPanicWithAbortHandler(t *testing.T) {
	const expectCode = 204

	var buf strings.Builder
	router := New()
	router.Use(RecoveryWithWriter(&buf))
	router.GET("/recovery", func(c *Context) {
		// Start writing response
		c.Header("X-Test", "Value")
		c.Status(expectCode)

		// Panic with ErrAbortHandler which should be treated as broken pipe
		panic(http.ErrAbortHandler)
	})
	// RUN
	w := PerformRequest(router, http.MethodGet, "/recovery")
	// TEST
	assert.Equal(t, expectCode, w.Code)
	out := buf.String()
	assert.Contains(t, out, "net/http: abort Handler")
	assert.NotContains(t, out, "panic recovered")
}

Domain

Subdomains

Analyze Your Own Codebase

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

Try Supermodel Free