[docs] Doc fix for testing variables in path (#374)
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 #373
This commit is contained in:
committed by
Matt Silverlock
parent
5e55a4adb8
commit
fdeb7bc314
@@ -601,8 +601,11 @@ func TestMetricsHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rr := httptest.NewRecorder()
|
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
|
// In this case, our MetricsHandler returns a non-200 response
|
||||||
// for a route variable it doesn't know about.
|
// for a route variable it doesn't know about.
|
||||||
|
|||||||
Reference in New Issue
Block a user