Skip to content

Commit

Permalink
Doc fix for testing variables in path
Browse files Browse the repository at this point in the history
The example in the README does not pass the request through a mux therefore the request variables from the path are never populated. Update the sample to create a minimum viable router to use.

Fixes gorilla#373
  • Loading branch information
swalberg authored May 13, 2018
1 parent 5e55a4a commit 9bc144b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,11 @@ func TestMetricsHandler(t *testing.T) {
}

rr := httptest.NewRecorder()
handler := http.HandlerFunc(MetricsHandler)
handler.ServeHTTP(rr, req)

// Need to create a router that we can pass the request through so that the vars will be added to the context
router := mux.NewRouter()
router.HandleFunc("/metrics/{type}", MetricsHandler)
router.ServeHTTP(rr, req)

// In this case, our MetricsHandler returns a non-200 response
// for a route variable it doesn't know about.
Expand Down

0 comments on commit 9bc144b

Please sign in to comment.