Browse Source

Covering change with unit test

This test focuses on the feature of allowing sub-routers error handlers to precede the parents, rather than the code change required to provide this functionality.
pull/139/head
Nate Woods 10 years ago
parent
commit
82a9c170d4
  1. 24
      mux_test.go

24
mux_test.go

@ -1123,6 +1123,30 @@ func TestWalkNested(t *testing.T) { @@ -1123,6 +1123,30 @@ func TestWalkNested(t *testing.T) {
}
}
func TestSubrouterErrorHandling(t *testing.T) {
superRouterCalled := false
subRouterCalled := false
router := NewRouter()
router.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
superRouterCalled = true
})
subRouter := router.PathPrefix("/bign8").Subrouter()
subRouter.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
subRouterCalled = true
})
req, _ := http.NewRequest("GET", "http://localhost/bign8/was/here", nil)
router.ServeHTTP(NewRecorder(), req)
if superRouterCalled {
t.Error("Super router 404 handler called when sub-router 404 handler is available.")
}
if !subRouterCalled {
t.Error("Sub-router 404 handler was not called.")
}
}
// ----------------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------------

Loading…
Cancel
Save