From 670af050eea6fbe5afbcfb0f4a057a94920d0061 Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Wed, 17 Nov 2021 14:04:43 +0300 Subject: [PATCH] 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. --- cli/options/options_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/options/options_test.go b/cli/options/options_test.go index 57ea27683..22ded55d6 100644 --- a/cli/options/options_test.go +++ b/cli/options/options_test.go @@ -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))) }) }