TestRouterNotFound() — gin Function Reference
Architecture documentation for the TestRouterNotFound() function in routes_test.go from the gin codebase.
Entity Profile
Dependency Diagram
graph TD a032efc7_7a66_7cfc_46c6_d3563bf3f9e3["TestRouterNotFound()"] 69c2add5_555a_3d82_a4e7_993886631a2c["PerformRequest()"] a032efc7_7a66_7cfc_46c6_d3563bf3f9e3 -->|calls| 69c2add5_555a_3d82_a4e7_993886631a2c style a032efc7_7a66_7cfc_46c6_d3563bf3f9e3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
routes_test.go lines 568–633
func TestRouterNotFound(t *testing.T) {
router := New()
router.RedirectFixedPath = true
router.GET("/path", func(c *Context) {})
router.GET("/dir/", func(c *Context) {})
router.GET("/", func(c *Context) {})
testRoutes := []struct {
route string
code int
location string
}{
{"/path/", http.StatusMovedPermanently, "/path"}, // TSR -/
{"/dir", http.StatusMovedPermanently, "/dir/"}, // TSR +/
{"/PATH", http.StatusMovedPermanently, "/path"}, // Fixed Case
{"/DIR/", http.StatusMovedPermanently, "/dir/"}, // Fixed Case
{"/PATH/", http.StatusMovedPermanently, "/path"}, // Fixed Case -/
{"/DIR", http.StatusMovedPermanently, "/dir/"}, // Fixed Case +/
{"/../path", http.StatusMovedPermanently, "/path"}, // Without CleanPath
{"/nope", http.StatusNotFound, ""}, // NotFound
}
for _, tr := range testRoutes {
w := PerformRequest(router, http.MethodGet, tr.route)
assert.Equal(t, tr.code, w.Code)
if w.Code != http.StatusNotFound {
assert.Equal(t, tr.location, w.Header().Get("Location"))
}
}
// Test custom not found handler
var notFound bool
router.NoRoute(func(c *Context) {
c.AbortWithStatus(http.StatusNotFound)
notFound = true
})
w := PerformRequest(router, http.MethodGet, "/nope")
assert.Equal(t, http.StatusNotFound, w.Code)
assert.True(t, notFound)
// Test other method than GET (want 307 instead of 301)
router.PATCH("/path", func(c *Context) {})
w = PerformRequest(router, http.MethodPatch, "/path/")
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
assert.Equal(t, "map[Location:[/path]]", fmt.Sprint(w.Header()))
// Test special case where no node for the prefix "/" exists
router = New()
router.GET("/a", func(c *Context) {})
w = PerformRequest(router, http.MethodGet, "/")
assert.Equal(t, http.StatusNotFound, w.Code)
// Reproduction test for the bug of issue #2843
router = New()
router.NoRoute(func(c *Context) {
if c.Request.RequestURI == "/login" {
c.String(http.StatusOK, "login")
}
})
router.GET("/logout", func(c *Context) {
c.String(http.StatusOK, "logout")
})
w = PerformRequest(router, http.MethodGet, "/login")
assert.Equal(t, "login", w.Body.String())
w = PerformRequest(router, http.MethodGet, "/logout")
assert.Equal(t, "logout", w.Body.String())
}
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does TestRouterNotFound() do?
TestRouterNotFound() is a function in the gin codebase.
What does TestRouterNotFound() call?
TestRouterNotFound() calls 1 function(s): PerformRequest.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free