@@ -502,6 +502,7 @@ func TestRouterLookup(t *testing.T) {
502
502
503
503
func TestRouterParamsFromContext (t * testing.T ) {
504
504
routed := false
505
+
505
506
wantParams := Params {Param {"name" , "gopher" }}
506
507
handlerFunc := func (_ http.ResponseWriter , req * http.Request ) {
507
508
// get params from request context
@@ -513,7 +514,20 @@ func TestRouterParamsFromContext(t *testing.T) {
513
514
514
515
routed = true
515
516
}
517
+
518
+ var nilParams Params
519
+ handlerFuncNil := func (_ http.ResponseWriter , req * http.Request ) {
520
+ // get params from request context
521
+ params := ParamsFromContext (req .Context ())
522
+
523
+ if ! reflect .DeepEqual (params , nilParams ) {
524
+ t .Fatalf ("Wrong parameter values: want %v, got %v" , nilParams , params )
525
+ }
526
+
527
+ routed = true
528
+ }
516
529
router := New ()
530
+ router .HandlerFunc (http .MethodGet , "/user" , handlerFuncNil )
517
531
router .HandlerFunc (http .MethodGet , "/user/:name" , handlerFunc )
518
532
519
533
w := new (mockResponseWriter )
@@ -522,6 +536,13 @@ func TestRouterParamsFromContext(t *testing.T) {
522
536
if ! routed {
523
537
t .Fatal ("Routing failed!" )
524
538
}
539
+
540
+ routed = false
541
+ r , _ = http .NewRequest (http .MethodGet , "/user" , nil )
542
+ router .ServeHTTP (w , r )
543
+ if ! routed {
544
+ t .Fatal ("Routing failed!" )
545
+ }
525
546
}
526
547
527
548
type mockFileSystem struct {
0 commit comments