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

Function TestContextMiddleware

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

Source from the content-addressed store, hash-verified

2858}
2859
2860func TestContextMiddleware(t *testing.T) {
2861 withTimeout := func(h http.Handler) http.Handler {
2862 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2863 ctx, cancel := context.WithTimeout(r.Context(), time.Minute)
2864 defer cancel()
2865 h.ServeHTTP(w, r.WithContext(ctx))
2866 })
2867 }
2868
2869 r := NewRouter()
2870 r.Handle("/path/{foo}", withTimeout(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2871 vars := Vars(r)
2872 if vars["foo"] != "bar" {
2873 t.Fatal("Expected foo var to be set")
2874 }
2875 })))
2876
2877 rec := NewRecorder()
2878 req := newRequest("GET", "/path/bar")
2879 r.ServeHTTP(rec, req)
2880}
2881
2882func TestGetVarNames(t *testing.T) {
2883 r := NewRouter()

Callers

nothing calls this directly

Calls 8

HandleMethod · 0.95
ServeHTTPMethod · 0.95
NewRouterFunction · 0.85
VarsFunction · 0.85
NewRecorderFunction · 0.85
newRequestFunction · 0.85
HandlerFuncMethod · 0.80
ServeHTTPMethod · 0.45

Tested by

no test coverage detected