cli: fix TestGetTimeoutContext test
Problem: ``` --- FAIL: TestGetTimeoutContext (0.00s) --- FAIL: TestGetTimeoutContext/default (0.00s) options_test.go:44: Error Trace: options_test.go:44 Error: Should be true Test: TestGetTimeoutContext/default --- FAIL: TestGetTimeoutContext/set (0.00s) options_test.go:55: Error Trace: options_test.go:55 Error: Should be true Test: TestGetTimeoutContext/set FAIL ``` Solution: Allow deadline be equal to expected end time.
This commit is contained in:
parent
c43c51dac1
commit
670af050ee
1 changed files with 4 additions and 4 deletions
|
@ -39,9 +39,9 @@ func TestGetTimeoutContext(t *testing.T) {
|
|||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
ctx := cli.NewContext(cli.NewApp(), set, nil)
|
||||
actualCtx, _ := GetTimeoutContext(ctx)
|
||||
end := time.Now()
|
||||
end := time.Now().Add(DefaultTimeout)
|
||||
dl, _ := actualCtx.Deadline()
|
||||
require.True(t, start.Before(dl) && dl.Before(end.Add(DefaultTimeout)))
|
||||
require.True(t, start.Before(dl) && (dl.Before(end) || dl.Equal(end)))
|
||||
})
|
||||
|
||||
t.Run("set", func(t *testing.T) {
|
||||
|
@ -50,8 +50,8 @@ func TestGetTimeoutContext(t *testing.T) {
|
|||
set.Duration("timeout", time.Duration(20), "")
|
||||
ctx := cli.NewContext(cli.NewApp(), set, nil)
|
||||
actualCtx, _ := GetTimeoutContext(ctx)
|
||||
end := time.Now()
|
||||
end := time.Now().Add(time.Nanosecond * 20)
|
||||
dl, _ := actualCtx.Deadline()
|
||||
require.True(t, start.Before(dl) && dl.Before(end.Add(time.Nanosecond*20)))
|
||||
require.True(t, start.Before(dl) && (dl.Before(end) || dl.Equal(end)))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue