(t *testing.T)
| 897 | } |
| 898 | |
| 899 | func TestServeMux_HandleMiddlewares(t *testing.T) { |
| 900 | var mws []int |
| 901 | mux := runtime.NewServeMux(runtime.WithMiddlewares( |
| 902 | func(next runtime.HandlerFunc) runtime.HandlerFunc { |
| 903 | return func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) { |
| 904 | mws = append(mws, 1) |
| 905 | next(w, r, pathParams) |
| 906 | } |
| 907 | }, |
| 908 | func(next runtime.HandlerFunc) runtime.HandlerFunc { |
| 909 | return func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) { |
| 910 | mws = append(mws, 2) |
| 911 | next(w, r, pathParams) |
| 912 | } |
| 913 | }, |
| 914 | )) |
| 915 | err := mux.HandlePath("GET", "/test", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) { |
| 916 | if len(mws) == 0 { |
| 917 | t.Errorf("middlewares not called") |
| 918 | } else if mws[0] != 1 { |
| 919 | t.Errorf("first middleware is not called first") |
| 920 | } else if mws[1] != 2 { |
| 921 | t.Errorf("second middleware is not called the second") |
| 922 | } |
| 923 | }) |
| 924 | if err != nil { |
| 925 | t.Errorf("The route test with method GET and path /test invalid, got %v", err) |
| 926 | } |
| 927 | |
| 928 | r := httptest.NewRequest("GET", "/test", nil) |
| 929 | w := httptest.NewRecorder() |
| 930 | mux.ServeHTTP(w, r) |
| 931 | if w.Code != 200 { |
| 932 | t.Errorf("request not processed") |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | func TestServeMux_InjectPattern(t *testing.T) { |
| 937 | mux := runtime.NewServeMux() |
nothing calls this directly
no test coverage detected