MCPcopy
hub / github.com/gorilla/mux / TestSubrouterErrorHandling

Function TestSubrouterErrorHandling

mux_test.go:1737–1759  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1735}
1736
1737func TestSubrouterErrorHandling(t *testing.T) {
1738 superRouterCalled := false
1739 subRouterCalled := false
1740
1741 router := NewRouter()
1742 router.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1743 superRouterCalled = true
1744 })
1745 subRouter := router.PathPrefix("/bign8").Subrouter()
1746 subRouter.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1747 subRouterCalled = true
1748 })
1749
1750 req, _ := http.NewRequest("GET", "http://localhost/bign8/was/here", nil)
1751 router.ServeHTTP(NewRecorder(), req)
1752
1753 if superRouterCalled {
1754 t.Error("Super router 404 handler called when sub-router 404 handler is available.")
1755 }
1756 if !subRouterCalled {
1757 t.Error("Sub-router 404 handler was not called.")
1758 }
1759}
1760
1761// See: https://github.com/gorilla/mux/issues/200
1762func TestPanicOnCapturingGroups(t *testing.T) {

Callers

nothing calls this directly

Calls 6

PathPrefixMethod · 0.95
ServeHTTPMethod · 0.95
NewRouterFunction · 0.85
NewRecorderFunction · 0.85
HandlerFuncMethod · 0.80
SubrouterMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…