From 1599ed2a5efd393516814f5efca67b8876d13fac Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Mon, 17 Jul 2023 04:21:05 -0400 Subject: [PATCH] Improve accuracy of test to assess return of time.Now() --- utils/coreutils_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils/coreutils_test.go b/utils/coreutils_test.go index 1f223e987..382c2eca3 100644 --- a/utils/coreutils_test.go +++ b/utils/coreutils_test.go @@ -828,9 +828,11 @@ func TestEndOfMonth(t *testing.T) { if !eom.Equal(expected) { t.Errorf("Expected %v was %v", expected, eom) } + // Date ref represents zero time instant, will return time.Now(). eom = GetEndOfMonth(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)) - if time.Now().Add(-1).Before(eom) { - t.Errorf("Expected %v was %v", expected, eom) + if currentDateRef := time.Now(); currentDateRef.Before(eom) || + time.Since(eom) > time.Millisecond { + t.Errorf("Expected GetEndOfMonth to return the current date info, received: %s", eom) } }