| 217 | } |
| 218 | |
| 219 | func BenchmarkAllowed(b *testing.B) { |
| 220 | handlerFunc := func(_ http.ResponseWriter, _ *http.Request, _ Params) {} |
| 221 | |
| 222 | router := New() |
| 223 | router.POST("/path", handlerFunc) |
| 224 | router.GET("/path", handlerFunc) |
| 225 | |
| 226 | b.Run("Global", func(b *testing.B) { |
| 227 | b.ReportAllocs() |
| 228 | for i := 0; i < b.N; i++ { |
| 229 | _ = router.allowed("*", http.MethodOptions) |
| 230 | } |
| 231 | }) |
| 232 | b.Run("Path", func(b *testing.B) { |
| 233 | b.ReportAllocs() |
| 234 | for i := 0; i < b.N; i++ { |
| 235 | _ = router.allowed("/path", http.MethodOptions) |
| 236 | } |
| 237 | }) |
| 238 | } |
| 239 | |
| 240 | func TestRouterOPTIONS(t *testing.T) { |
| 241 | handlerFunc := func(_ http.ResponseWriter, _ *http.Request, _ Params) {} |