(t *testing.T)
| 2031 | } |
| 2032 | |
| 2033 | func TestNoMatchMethodErrorHandler(t *testing.T) { |
| 2034 | func1 := func(w http.ResponseWriter, r *http.Request) {} |
| 2035 | |
| 2036 | r := NewRouter() |
| 2037 | r.HandleFunc("/", func1).Methods("GET", "POST") |
| 2038 | |
| 2039 | req, _ := http.NewRequest("PUT", "http://localhost/", nil) |
| 2040 | match := new(RouteMatch) |
| 2041 | matched := r.Match(req, match) |
| 2042 | |
| 2043 | if matched { |
| 2044 | t.Error("Should not have matched route for methods") |
| 2045 | } |
| 2046 | |
| 2047 | if match.MatchErr != ErrMethodMismatch { |
| 2048 | t.Error("Should get ErrMethodMismatch error") |
| 2049 | } |
| 2050 | |
| 2051 | resp := NewRecorder() |
| 2052 | r.ServeHTTP(resp, req) |
| 2053 | if resp.Code != http.StatusMethodNotAllowed { |
| 2054 | t.Errorf("Expecting code %v", 405) |
| 2055 | } |
| 2056 | |
| 2057 | // Add matching route |
| 2058 | r.HandleFunc("/", func1).Methods("PUT") |
| 2059 | |
| 2060 | match = new(RouteMatch) |
| 2061 | matched = r.Match(req, match) |
| 2062 | |
| 2063 | if !matched { |
| 2064 | t.Error("Should have matched route for methods") |
| 2065 | } |
| 2066 | |
| 2067 | if match.MatchErr != nil { |
| 2068 | t.Error("Should not have any matching error. Found:", match.MatchErr) |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | func TestMultipleDefinitionOfSamePathWithDifferentMethods(t *testing.T) { |
| 2073 | emptyHandler := func(w http.ResponseWriter, r *http.Request) {} |
nothing calls this directly
no test coverage detected