@@ -64,6 +64,9 @@ Verbose: true
6464` ,
6565 }
6666
67+ minuteDuration := time .Minute
68+ secondDuration := time .Second
69+
6770 routes := []featuredRoutes {
6871 {
6972 jwt : jwtSetting {},
@@ -73,7 +76,7 @@ Verbose: true
7376 Path : "/" ,
7477 Handler : func (w http.ResponseWriter , r * http.Request ) {},
7578 }},
76- timeout : time . Minute ,
79+ timeout : & minuteDuration ,
7780 },
7881 {
7982 priority : true ,
@@ -84,7 +87,7 @@ Verbose: true
8487 Path : "/" ,
8588 Handler : func (w http.ResponseWriter , r * http.Request ) {},
8689 }},
87- timeout : time . Second ,
90+ timeout : & secondDuration ,
8891 },
8992 {
9093 priority : true ,
@@ -227,19 +230,23 @@ Verbose: true
227230 }))
228231
229232 timeout := time .Second * 3
230- if route .timeout > timeout {
231- timeout = route .timeout
233+ if route .timeout != nil {
234+ timeout = * route .timeout
232235 }
233236 assert .Equal (t , timeout , ng .timeout )
234237 })
235238 }
236239 }
237240}
238241
242+ func getPtrTimeDuration (dur time.Duration ) * time.Duration {
243+ return & dur
244+ }
245+
239246func TestEngine_checkedTimeout (t * testing.T ) {
240247 tests := []struct {
241248 name string
242- timeout time.Duration
249+ timeout * time.Duration
243250 expect time.Duration
244251 }{
245252 {
@@ -248,19 +255,24 @@ func TestEngine_checkedTimeout(t *testing.T) {
248255 },
249256 {
250257 name : "less" ,
251- timeout : time .Millisecond * 500 ,
258+ timeout : getPtrTimeDuration ( time .Millisecond * 500 ) ,
252259 expect : time .Millisecond * 500 ,
253260 },
254261 {
255262 name : "equal" ,
256- timeout : time .Second ,
263+ timeout : getPtrTimeDuration ( time .Second ) ,
257264 expect : time .Second ,
258265 },
259266 {
260267 name : "more" ,
261- timeout : time .Millisecond * 1500 ,
268+ timeout : getPtrTimeDuration ( time .Millisecond * 1500 ) ,
262269 expect : time .Millisecond * 1500 ,
263270 },
271+ {
272+ name : "set zero" ,
273+ timeout : getPtrTimeDuration (0 ),
274+ expect : 0 ,
275+ },
264276 }
265277
266278 ng := newEngine (RestConf {
0 commit comments