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

Function TestMiddlewareAdd

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

Source from the content-addressed store, hash-verified

20func dummyHandler(w http.ResponseWriter, r *http.Request) {}
21
22func TestMiddlewareAdd(t *testing.T) {
23 router := NewRouter()
24 router.HandleFunc("/", dummyHandler).Methods("GET")
25
26 mw := &testMiddleware{}
27
28 router.useInterface(mw)
29 if len(router.middlewares) != 1 || router.middlewares[0] != mw {
30 t.Fatal("Middleware interface was not added correctly")
31 }
32
33 router.Use(mw.Middleware)
34 if len(router.middlewares) != 2 {
35 t.Fatal("Middleware method was not added correctly")
36 }
37
38 banalMw := func(handler http.Handler) http.Handler {
39 return handler
40 }
41 router.Use(banalMw)
42 if len(router.middlewares) != 3 {
43 t.Fatal("Middleware function was not added correctly")
44 }
45}
46
47func TestMiddleware(t *testing.T) {
48 router := NewRouter()

Callers

nothing calls this directly

Calls 5

HandleFuncMethod · 0.95
useInterfaceMethod · 0.95
UseMethod · 0.95
NewRouterFunction · 0.85
MethodsMethod · 0.45

Tested by

no test coverage detected