From d115a1a1e1c1acf5f5aaa46ad3eed1ab4751908f Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Thu, 6 Apr 2017 13:38:31 -0600 Subject: [PATCH] tools/time_tools: test tools.IsExpiredAtOrIn --- tools/time_tools_test.go | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tools/time_tools_test.go b/tools/time_tools_test.go index 6a9a7337..708fa132 100644 --- a/tools/time_tools_test.go +++ b/tools/time_tools_test.go @@ -34,3 +34,63 @@ func TestTimeAtOrInZeroTime(t *testing.T) { assert.Equal(t, zero, got) } + +func TestIsExpiredAtOrInWithNonZeroTime(t *testing.T) { + now := time.Now() + within := 5 * time.Minute + at := now.Add(10 * time.Minute) + in := time.Duration(0) + + expired, ok := IsExpiredAtOrIn(now, within, at, in) + + assert.False(t, ok) + assert.Equal(t, at, expired) +} + +func TestIsExpiredAtOrInWithNonZeroDuration(t *testing.T) { + now := time.Now() + within := 5 * time.Minute + at := time.Time{} + in := 10 * time.Minute + + expired, ok := IsExpiredAtOrIn(now, within, at, in) + + assert.Equal(t, now.Add(in), expired) + assert.False(t, ok) +} + +func TestIsExpiredAtOrInWithNonZeroTimeExpired(t *testing.T) { + now := time.Now() + within := 5 * time.Minute + at := now.Add(3 * time.Minute) + in := time.Duration(0) + + expired, ok := IsExpiredAtOrIn(now, within, at, in) + + assert.True(t, ok) + assert.Equal(t, at, expired) +} + +func TestIsExpiredAtOrInWithNonZeroDurationExpired(t *testing.T) { + now := time.Now() + within := 5 * time.Minute + at := time.Time{} + in := -10 * time.Minute + + expired, ok := IsExpiredAtOrIn(now, within, at, in) + + assert.Equal(t, now.Add(in), expired) + assert.True(t, ok) +} + +func TestIsExpiredAtOrInWithAmbiguousTime(t *testing.T) { + now := time.Now() + within := 5 * time.Minute + at := now.Add(-10 * time.Minute) + in := 10 * time.Minute + + expired, ok := IsExpiredAtOrIn(now, within, at, in) + + assert.Equal(t, now.Add(in), expired) + assert.False(t, ok) +}