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

Function TestCORSMethodMiddlewareSubrouter

middleware_test.go:529–547  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

527}
528
529func TestCORSMethodMiddlewareSubrouter(t *testing.T) {
530 router := NewRouter().StrictSlash(true)
531
532 subrouter := router.PathPrefix("/test").Subrouter()
533 subrouter.HandleFunc("/hello", stringHandler("a")).Methods(http.MethodGet, http.MethodOptions, http.MethodPost)
534 subrouter.HandleFunc("/hello/{name}", stringHandler("b")).Methods(http.MethodGet, http.MethodOptions)
535
536 subrouter.Use(CORSMethodMiddleware(subrouter))
537
538 rw := NewRecorder()
539 req := newRequest("GET", "/test/hello/asdf")
540 router.ServeHTTP(rw, req)
541
542 actualMethods := rw.Header().Get("Access-Control-Allow-Methods")
543 expectedMethods := "GET,OPTIONS"
544 if actualMethods != expectedMethods {
545 t.Fatalf("expected methods %q but got: %q", expectedMethods, actualMethods)
546 }
547}
548
549func TestMiddlewareOnMultiSubrouter(t *testing.T) {
550 first := "first"

Callers

nothing calls this directly

Calls 14

NewRouterFunction · 0.85
stringHandlerFunction · 0.85
CORSMethodMiddlewareFunction · 0.85
NewRecorderFunction · 0.85
newRequestFunction · 0.85
StrictSlashMethod · 0.80
SubrouterMethod · 0.80
HandleFuncMethod · 0.80
UseMethod · 0.80
GetMethod · 0.80
PathPrefixMethod · 0.45
MethodsMethod · 0.45

Tested by

no test coverage detected