@@ -25,6 +25,7 @@ import (
25
25
26
26
"github.com/gofiber/utils/v2"
27
27
28
+ "github.com/stretchr/testify/assert"
28
29
"github.com/stretchr/testify/require"
29
30
"github.com/valyala/fasthttp"
30
31
"github.com/valyala/fasthttp/fasthttputil"
@@ -197,6 +198,7 @@ func (*customConstraint) Execute(param string, args ...string) bool {
197
198
}
198
199
199
200
func Test_App_CustomConstraint (t * testing.T ) {
201
+ t .Parallel ()
200
202
app := New ()
201
203
app .RegisterCustomConstraint (& customConstraint {})
202
204
@@ -821,20 +823,20 @@ func Test_App_ShutdownWithTimeout(t *testing.T) {
821
823
time .Sleep (5 * time .Second )
822
824
return c .SendString ("body" )
823
825
})
826
+
824
827
ln := fasthttputil .NewInmemoryListener ()
825
828
go func () {
826
- require .NoError (t , app .Listener (ln ))
829
+ err := app .Listener (ln )
830
+ assert .NoError (t , err )
827
831
}()
832
+
828
833
time .Sleep (1 * time .Second )
829
834
go func () {
830
835
conn , err := ln .Dial ()
831
- if err != nil {
832
- t .Errorf ("unexepcted error: %v" , err )
833
- }
836
+ assert .NoError (t , err )
834
837
835
- if _ , err = conn .Write ([]byte ("GET / HTTP/1.1\r \n Host: google.com\r \n \r \n " )); err != nil {
836
- t .Errorf ("unexpected error: %v" , err )
837
- }
838
+ _ , err = conn .Write ([]byte ("GET / HTTP/1.1\r \n Host: google.com\r \n \r \n " ))
839
+ assert .NoError (t , err )
838
840
}()
839
841
time .Sleep (1 * time .Second )
840
842
@@ -866,20 +868,18 @@ func Test_App_ShutdownWithContext(t *testing.T) {
866
868
ln := fasthttputil .NewInmemoryListener ()
867
869
868
870
go func () {
869
- require .NoError (t , app .Listener (ln ))
871
+ err := app .Listener (ln )
872
+ assert .NoError (t , err )
870
873
}()
871
874
872
875
time .Sleep (1 * time .Second )
873
876
874
877
go func () {
875
878
conn , err := ln .Dial ()
876
- if err != nil {
877
- t .Errorf ("unexepcted error: %v" , err )
878
- }
879
+ assert .NoError (t , err )
879
880
880
- if _ , err = conn .Write ([]byte ("GET / HTTP/1.1\r \n Host: google.com\r \n \r \n " )); err != nil {
881
- t .Errorf ("unexpected error: %v" , err )
882
- }
881
+ _ , err = conn .Write ([]byte ("GET / HTTP/1.1\r \n Host: google.com\r \n \r \n " ))
882
+ assert .NoError (t , err )
883
883
}()
884
884
885
885
time .Sleep (1 * time .Second )
@@ -903,6 +903,7 @@ func Test_App_ShutdownWithContext(t *testing.T) {
903
903
904
904
// go test -run Test_App_Static_Index_Default
905
905
func Test_App_Static_Index_Default (t * testing.T ) {
906
+ t .Parallel ()
906
907
app := New ()
907
908
908
909
app .Static ("/prefix" , "./.github/workflows" )
@@ -932,6 +933,7 @@ func Test_App_Static_Index_Default(t *testing.T) {
932
933
933
934
// go test -run Test_App_Static_Index
934
935
func Test_App_Static_Direct (t * testing.T ) {
936
+ t .Parallel ()
935
937
app := New ()
936
938
937
939
app .Static ("/" , "./.github" )
@@ -960,6 +962,7 @@ func Test_App_Static_Direct(t *testing.T) {
960
962
961
963
// go test -run Test_App_Static_MaxAge
962
964
func Test_App_Static_MaxAge (t * testing.T ) {
965
+ t .Parallel ()
963
966
app := New ()
964
967
965
968
app .Static ("/" , "./.github" , Static {MaxAge : 100 })
@@ -974,6 +977,7 @@ func Test_App_Static_MaxAge(t *testing.T) {
974
977
975
978
// go test -run Test_App_Static_Custom_CacheControl
976
979
func Test_App_Static_Custom_CacheControl (t * testing.T ) {
980
+ t .Parallel ()
977
981
app := New ()
978
982
979
983
app .Static ("/" , "./.github" , Static {ModifyResponse : func (c Ctx ) error {
@@ -994,6 +998,7 @@ func Test_App_Static_Custom_CacheControl(t *testing.T) {
994
998
995
999
// go test -run Test_App_Static_Download
996
1000
func Test_App_Static_Download (t * testing.T ) {
1001
+ t .Parallel ()
997
1002
app := New ()
998
1003
999
1004
app .Static ("/fiber.png" , "./.github/testdata/fs/img/fiber.png" , Static {Download : true })
@@ -1008,6 +1013,7 @@ func Test_App_Static_Download(t *testing.T) {
1008
1013
1009
1014
// go test -run Test_App_Static_Group
1010
1015
func Test_App_Static_Group (t * testing.T ) {
1016
+ t .Parallel ()
1011
1017
app := New ()
1012
1018
1013
1019
grp := app .Group ("/v1" , func (c Ctx ) error {
@@ -1037,6 +1043,7 @@ func Test_App_Static_Group(t *testing.T) {
1037
1043
}
1038
1044
1039
1045
func Test_App_Static_Wildcard (t * testing.T ) {
1046
+ t .Parallel ()
1040
1047
app := New ()
1041
1048
1042
1049
app .Static ("*" , "./.github/index.html" )
@@ -1054,6 +1061,7 @@ func Test_App_Static_Wildcard(t *testing.T) {
1054
1061
}
1055
1062
1056
1063
func Test_App_Static_Prefix_Wildcard (t * testing.T ) {
1064
+ t .Parallel ()
1057
1065
app := New ()
1058
1066
1059
1067
app .Static ("/test/*" , "./.github/index.html" )
@@ -1079,6 +1087,7 @@ func Test_App_Static_Prefix_Wildcard(t *testing.T) {
1079
1087
}
1080
1088
1081
1089
func Test_App_Static_Prefix (t * testing.T ) {
1090
+ t .Parallel ()
1082
1091
app := New ()
1083
1092
app .Static ("/john" , "./.github" )
1084
1093
@@ -1109,6 +1118,7 @@ func Test_App_Static_Prefix(t *testing.T) {
1109
1118
}
1110
1119
1111
1120
func Test_App_Static_Trailing_Slash (t * testing.T ) {
1121
+ t .Parallel ()
1112
1122
app := New ()
1113
1123
app .Static ("/john" , "./.github" )
1114
1124
@@ -1155,6 +1165,7 @@ func Test_App_Static_Trailing_Slash(t *testing.T) {
1155
1165
}
1156
1166
1157
1167
func Test_App_Static_Next (t * testing.T ) {
1168
+ t .Parallel ()
1158
1169
app := New ()
1159
1170
app .Static ("/" , ".github" , Static {
1160
1171
Next : func (c Ctx ) bool {
@@ -1168,6 +1179,7 @@ func Test_App_Static_Next(t *testing.T) {
1168
1179
})
1169
1180
1170
1181
t .Run ("app.Static is skipped: invoking Get handler" , func (t * testing.T ) {
1182
+ t .Parallel ()
1171
1183
req := httptest .NewRequest (MethodGet , "/" , nil )
1172
1184
req .Header .Set ("X-Custom-Header" , "skip" )
1173
1185
resp , err := app .Test (req )
@@ -1182,6 +1194,7 @@ func Test_App_Static_Next(t *testing.T) {
1182
1194
})
1183
1195
1184
1196
t .Run ("app.Static is not skipped: serving index.html" , func (t * testing.T ) {
1197
+ t .Parallel ()
1185
1198
req := httptest .NewRequest (MethodGet , "/" , nil )
1186
1199
req .Header .Set ("X-Custom-Header" , "don't skip" )
1187
1200
resp , err := app .Test (req )
@@ -1198,6 +1211,7 @@ func Test_App_Static_Next(t *testing.T) {
1198
1211
1199
1212
// go test -run Test_App_Mixed_Routes_WithSameLen
1200
1213
func Test_App_Mixed_Routes_WithSameLen (t * testing.T ) {
1214
+ t .Parallel ()
1201
1215
app := New ()
1202
1216
1203
1217
// middleware
@@ -1476,6 +1490,7 @@ func (invalidView) Render(io.Writer, string, any, ...string) error { panic("impl
1476
1490
1477
1491
// go test -run Test_App_Init_Error_View
1478
1492
func Test_App_Init_Error_View (t * testing.T ) {
1493
+ t .Parallel ()
1479
1494
app := New (Config {Views : invalidView {}})
1480
1495
1481
1496
defer func () {
@@ -1542,23 +1557,23 @@ func Test_App_ReadTimeout(t *testing.T) {
1542
1557
time .Sleep (500 * time .Millisecond )
1543
1558
1544
1559
conn , err := net .Dial (NetworkTCP4 , "127.0.0.1:4004" )
1545
- require .NoError (t , err )
1560
+ assert .NoError (t , err )
1546
1561
defer func (conn net.Conn ) {
1547
1562
err := conn .Close ()
1548
- require .NoError (t , err )
1563
+ assert .NoError (t , err )
1549
1564
}(conn )
1550
1565
1551
1566
_ , err = conn .Write ([]byte ("HEAD /read-timeout HTTP/1.1\r \n " ))
1552
- require .NoError (t , err )
1567
+ assert .NoError (t , err )
1553
1568
1554
1569
buf := make ([]byte , 1024 )
1555
1570
var n int
1556
1571
n , err = conn .Read (buf )
1557
1572
1558
- require .NoError (t , err )
1559
- require .True (t , bytes .Contains (buf [:n ], []byte ("408 Request Timeout" )))
1573
+ assert .NoError (t , err )
1574
+ assert .True (t , bytes .Contains (buf [:n ], []byte ("408 Request Timeout" )))
1560
1575
1561
- require .NoError (t , app .Shutdown ())
1576
+ assert .NoError (t , app .Shutdown ())
1562
1577
}()
1563
1578
1564
1579
require .NoError (t , app .Listen (":4004" , ListenConfig {DisableStartupMessage : true }))
@@ -1576,23 +1591,22 @@ func Test_App_BadRequest(t *testing.T) {
1576
1591
go func () {
1577
1592
time .Sleep (500 * time .Millisecond )
1578
1593
conn , err := net .Dial (NetworkTCP4 , "127.0.0.1:4005" )
1579
- require .NoError (t , err )
1594
+ assert .NoError (t , err )
1580
1595
defer func (conn net.Conn ) {
1581
1596
err := conn .Close ()
1582
- require .NoError (t , err )
1597
+ assert .NoError (t , err )
1583
1598
}(conn )
1584
1599
1585
1600
_ , err = conn .Write ([]byte ("BadRequest\r \n " ))
1586
- require .NoError (t , err )
1601
+ assert .NoError (t , err )
1587
1602
1588
1603
buf := make ([]byte , 1024 )
1589
1604
var n int
1590
1605
n , err = conn .Read (buf )
1591
- require .NoError (t , err )
1592
-
1593
- require .True (t , bytes .Contains (buf [:n ], []byte ("400 Bad Request" )))
1594
1606
1595
- require .NoError (t , app .Shutdown ())
1607
+ assert .NoError (t , err )
1608
+ assert .True (t , bytes .Contains (buf [:n ], []byte ("400 Bad Request" )))
1609
+ assert .NoError (t , app .Shutdown ())
1596
1610
}()
1597
1611
1598
1612
require .NoError (t , app .Listen (":4005" , ListenConfig {DisableStartupMessage : true }))
@@ -1612,12 +1626,12 @@ func Test_App_SmallReadBuffer(t *testing.T) {
1612
1626
go func () {
1613
1627
time .Sleep (500 * time .Millisecond )
1614
1628
req , err := http .NewRequestWithContext (context .Background (), MethodGet , "http://127.0.0.1:4006/small-read-buffer" , nil )
1615
- require .NoError (t , err )
1629
+ assert .NoError (t , err )
1616
1630
var client http.Client
1617
1631
resp , err := client .Do (req )
1618
- require .NoError (t , err )
1619
- require .Equal (t , 431 , resp .StatusCode )
1620
- require .NoError (t , app .Shutdown ())
1632
+ assert .NoError (t , err )
1633
+ assert .Equal (t , 431 , resp .StatusCode )
1634
+ assert .NoError (t , app .Shutdown ())
1621
1635
}()
1622
1636
1623
1637
require .NoError (t , app .Listen (":4006" , ListenConfig {DisableStartupMessage : true }))
@@ -1755,6 +1769,19 @@ func Test_App_Test_no_timeout_infinitely(t *testing.T) {
1755
1769
}
1756
1770
}
1757
1771
1772
+ func Test_App_Test_timeout (t * testing.T ) {
1773
+ t .Parallel ()
1774
+
1775
+ app := New ()
1776
+ app .Get ("/" , func (_ Ctx ) error {
1777
+ time .Sleep (1 * time .Second )
1778
+ return nil
1779
+ })
1780
+
1781
+ _ , err := app .Test (httptest .NewRequest (MethodGet , "/" , nil ), 100 * time .Millisecond )
1782
+ require .Equal (t , errors .New ("test: timeout error after 100ms" ), err )
1783
+ }
1784
+
1758
1785
func Test_App_SetTLSHandler (t * testing.T ) {
1759
1786
t .Parallel ()
1760
1787
tlsHandler := & TLSHandler {clientHelloInfo : & tls.ClientHelloInfo {
@@ -1815,6 +1842,7 @@ func TestApp_GetRoutes(t *testing.T) {
1815
1842
}
1816
1843
1817
1844
func Test_Middleware_Route_Naming_With_Use (t * testing.T ) {
1845
+ t .Parallel ()
1818
1846
named := "named"
1819
1847
app := New ()
1820
1848
@@ -1874,6 +1902,7 @@ func Test_Middleware_Route_Naming_With_Use(t *testing.T) {
1874
1902
}
1875
1903
1876
1904
func Test_Route_Naming_Issue_2671_2685 (t * testing.T ) {
1905
+ t .Parallel ()
1877
1906
app := New ()
1878
1907
1879
1908
app .Get ("/" , emptyHandler ).Name ("index" )
0 commit comments