@@ -312,6 +312,8 @@ func TestRouterChaining(t *testing.T) {
312
312
func TestRouterGroup (t * testing.T ) {
313
313
r1 := New ()
314
314
r2 := r1 .Group ("/boo" )
315
+ r3 := r1 .Group ("/goo" )
316
+ r4 := r1 .Group ("/moo" )
315
317
fooHit := false
316
318
r1 .POST ("/foo" , func (ctx * fasthttp.RequestCtx ) {
317
319
fooHit = true
@@ -323,7 +325,14 @@ func TestRouterGroup(t *testing.T) {
323
325
barHit = true
324
326
ctx .SetStatusCode (fasthttp .StatusOK )
325
327
})
326
-
328
+ r3 .POST ("/bar" , func (ctx * fasthttp.RequestCtx ) {
329
+ barHit = true
330
+ ctx .SetStatusCode (fasthttp .StatusOK )
331
+ })
332
+ r4 .POST ("/bar" , func (ctx * fasthttp.RequestCtx ) {
333
+ barHit = true
334
+ ctx .SetStatusCode (fasthttp .StatusOK )
335
+ })
327
336
s := & fasthttp.Server {
328
337
Handler : r1 .Handler ,
329
338
}
@@ -369,7 +378,47 @@ func TestRouterGroup(t *testing.T) {
369
378
t .Fatalf ("Unexpected error when reading response: %s" , err )
370
379
}
371
380
if ! (resp .Header .StatusCode () == fasthttp .StatusOK && barHit ) {
372
- t .Errorf ("Chained routing failed with router chaining." )
381
+ t .Errorf ("Chained routing failed with router grouping." )
382
+ t .FailNow ()
383
+ }
384
+
385
+ rw .r .WriteString ("POST /goo/bar HTTP/1.1\r \n \r \n " )
386
+ go func () {
387
+ ch <- s .ServeConn (rw )
388
+ }()
389
+ select {
390
+ case err := <- ch :
391
+ if err != nil {
392
+ t .Fatalf ("return error %s" , err )
393
+ }
394
+ case <- time .After (100 * time .Millisecond ):
395
+ t .Fatalf ("timeout" )
396
+ }
397
+ if err := resp .Read (br ); err != nil {
398
+ t .Fatalf ("Unexpected error when reading response: %s" , err )
399
+ }
400
+ if ! (resp .Header .StatusCode () == fasthttp .StatusOK && barHit ) {
401
+ t .Errorf ("Chained routing failed with router grouping." )
402
+ t .FailNow ()
403
+ }
404
+
405
+ rw .r .WriteString ("POST /moo/bar HTTP/1.1\r \n \r \n " )
406
+ go func () {
407
+ ch <- s .ServeConn (rw )
408
+ }()
409
+ select {
410
+ case err := <- ch :
411
+ if err != nil {
412
+ t .Fatalf ("return error %s" , err )
413
+ }
414
+ case <- time .After (100 * time .Millisecond ):
415
+ t .Fatalf ("timeout" )
416
+ }
417
+ if err := resp .Read (br ); err != nil {
418
+ t .Fatalf ("Unexpected error when reading response: %s" , err )
419
+ }
420
+ if ! (resp .Header .StatusCode () == fasthttp .StatusOK && barHit ) {
421
+ t .Errorf ("Chained routing failed with router grouping." )
373
422
t .FailNow ()
374
423
}
375
424
0 commit comments