@@ -288,3 +288,40 @@ func TestRoutesWithPrefix(t *testing.T) {
288
288
}
289
289
}
290
290
}
291
+
292
+ func TestRouteVerbs (t * testing.T ) {
293
+ router := New (Context {})
294
+ router .Get ("/a" , func (w ResponseWriter , r * Request ) {
295
+ fmt .Fprintf (w , "GET" )
296
+ })
297
+ router .Put ("/a" , func (w ResponseWriter , r * Request ) {
298
+ fmt .Fprintf (w , "PUT" )
299
+ })
300
+ router .Post ("/a" , func (w ResponseWriter , r * Request ) {
301
+ fmt .Fprintf (w , "POST" )
302
+ })
303
+ router .Delete ("/a" , func (w ResponseWriter , r * Request ) {
304
+ fmt .Fprintf (w , "DELETE" )
305
+ })
306
+ router .Patch ("/a" , func (w ResponseWriter , r * Request ) {
307
+ fmt .Fprintf (w , "PATCH" )
308
+ })
309
+
310
+ for _ , method := range HTTPMethods {
311
+ method := string (method )
312
+
313
+ recorder := httptest .NewRecorder ()
314
+ request , _ := http .NewRequest (method , "/a" , nil )
315
+
316
+ router .ServeHTTP (recorder , request )
317
+
318
+ if recorder .Code != 200 {
319
+ t .Error ("Test:" , method , " Didn't get Code=200. Got Code=" , recorder .Code )
320
+ }
321
+
322
+ body := strings .TrimSpace (string (recorder .Body .Bytes ()))
323
+ if body != method {
324
+ t .Error ("Test:" , method , " Didn't get Body=" , method , ". Got Body=" , body )
325
+ }
326
+ }
327
+ }
0 commit comments