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

Function TestMethodNotAllowed

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

Source from the content-addressed store, hash-verified

2769}
2770
2771func TestMethodNotAllowed(t *testing.T) {
2772 handler := func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) }
2773 router := NewRouter()
2774 router.HandleFunc("/thing", handler).Methods(http.MethodGet)
2775 router.HandleFunc("/something", handler).Methods(http.MethodGet)
2776
2777 w := NewRecorder()
2778 req := newRequest(http.MethodPut, "/thing")
2779
2780 router.ServeHTTP(w, req)
2781
2782 if w.Code != http.StatusMethodNotAllowed {
2783 t.Fatalf("Expected status code 405 (got %d)", w.Code)
2784 }
2785}
2786
2787type customMethodNotAllowedHandler struct {
2788 msg string

Callers

nothing calls this directly

Calls 7

HandleFuncMethod · 0.95
ServeHTTPMethod · 0.95
NewRouterFunction · 0.85
NewRecorderFunction · 0.85
newRequestFunction · 0.85
WriteHeaderMethod · 0.45
MethodsMethod · 0.45

Tested by

no test coverage detected