@@ -691,24 +691,32 @@ func TestMuxHandlePatternValidation(t *testing.T) {
691
691
t .Run (tc .name , func (t * testing.T ) {
692
692
defer func () {
693
693
if r := recover (); r != nil && ! tc .shouldPanic {
694
- t .Errorf ("Unexpected panic for pattern %s" , tc .pattern )
694
+ t .Errorf ("Unexpected panic for pattern %s: \n %v " , tc .pattern , r )
695
695
}
696
696
}()
697
697
698
- r := NewRouter ()
699
- r .Handle (tc .pattern , http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
698
+ r1 := NewRouter ()
699
+ r1 .Handle (tc .pattern , http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
700
700
w .Write ([]byte (tc .expectedBody ))
701
701
}))
702
702
703
+ // Test that HandleFunc also handles method patterns
704
+ r2 := NewRouter ()
705
+ r2 .HandleFunc (tc .pattern , func (w http.ResponseWriter , r * http.Request ) {
706
+ w .Write ([]byte (tc .expectedBody ))
707
+ })
708
+
703
709
if ! tc .shouldPanic {
704
- // Use testRequest for valid patterns
705
- ts := httptest .NewServer (r )
706
- defer ts .Close ()
707
-
708
- resp , body := testRequest (t , ts , tc .method , tc .path , nil )
709
- if body != tc .expectedBody || resp .StatusCode != tc .expectedStatus {
710
- t .Errorf ("Expected status %d and body %s; got status %d and body %s for pattern %s" ,
711
- tc .expectedStatus , tc .expectedBody , resp .StatusCode , body , tc .pattern )
710
+ for _ , r := range []Router {r1 , r2 } {
711
+ // Use testRequest for valid patterns
712
+ ts := httptest .NewServer (r )
713
+ defer ts .Close ()
714
+
715
+ resp , body := testRequest (t , ts , tc .method , tc .path , nil )
716
+ if body != tc .expectedBody || resp .StatusCode != tc .expectedStatus {
717
+ t .Errorf ("Expected status %d and body %s; got status %d and body %s for pattern %s" ,
718
+ tc .expectedStatus , tc .expectedBody , resp .StatusCode , body , tc .pattern )
719
+ }
712
720
}
713
721
}
714
722
})
0 commit comments