Skip to content

Commit be82bf4

Browse files
SpectatorNankevwan
authored andcommitted
fix: update timeout test incorrect
1 parent 8a3b353 commit be82bf4

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

rest/engine_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,14 @@ Verbose: true
239239
}
240240
}
241241

242+
func getPtrTimeDuration(dur time.Duration) *time.Duration {
243+
return &dur
244+
}
245+
242246
func TestEngine_checkedTimeout(t *testing.T) {
243247
tests := []struct {
244248
name string
245-
timeout time.Duration
249+
timeout *time.Duration
246250
expect time.Duration
247251
}{
248252
{
@@ -251,26 +255,31 @@ func TestEngine_checkedTimeout(t *testing.T) {
251255
},
252256
{
253257
name: "less",
254-
timeout: time.Millisecond * 500,
258+
timeout: getPtrTimeDuration(time.Millisecond * 500),
255259
expect: time.Millisecond * 500,
256260
},
257261
{
258262
name: "equal",
259-
timeout: time.Second,
263+
timeout: getPtrTimeDuration(time.Second),
260264
expect: time.Second,
261265
},
262266
{
263267
name: "more",
264-
timeout: time.Millisecond * 1500,
268+
timeout: getPtrTimeDuration(time.Millisecond * 1500),
265269
expect: time.Millisecond * 1500,
266270
},
271+
{
272+
name: "set zero",
273+
timeout: getPtrTimeDuration(0),
274+
expect: 0,
275+
},
267276
}
268277

269278
ng := newEngine(RestConf{
270279
Timeout: 1000,
271280
})
272281
for _, test := range tests {
273-
assert.Equal(t, test.expect, ng.checkedTimeout(&test.timeout))
282+
assert.Equal(t, test.expect, ng.checkedTimeout(test.timeout))
274283
}
275284
}
276285

rest/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func TestWithPriority(t *testing.T) {
345345
func TestWithTimeout(t *testing.T) {
346346
var fr featuredRoutes
347347
WithTimeout(time.Hour)(&fr)
348-
assert.Equal(t, time.Hour, fr.timeout)
348+
assert.Equal(t, time.Hour, *fr.timeout)
349349
}
350350

351351
func TestWithTLSConfig(t *testing.T) {

0 commit comments

Comments
 (0)