From 20afc011fb03fb514304a7a79d0e4fe124e54461 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Thu, 20 Jul 2023 11:33:59 -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 0ace1e3f1..d1ee664d1 100644 --- a/utils/coreutils_test.go +++ b/utils/coreutils_test.go @@ -938,9 +938,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) } }