github.com/x-oss-byte/git-lfs@v2.5.2+incompatible/tools/time_tools_test.go (about) 1 package tools 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestTimeAtOrInNoDuration(t *testing.T) { 11 now := time.Now() 12 then := time.Now().Add(24 * time.Hour) 13 14 got := TimeAtOrIn(now, then, time.Duration(0)) 15 16 assert.Equal(t, then, got) 17 } 18 19 func TestTimeAtOrInWithDuration(t *testing.T) { 20 now := time.Now() 21 duration := 5 * time.Minute 22 expected := now.Add(duration) 23 24 got := TimeAtOrIn(now, now, duration) 25 26 assert.Equal(t, expected, got) 27 } 28 29 func TestTimeAtOrInZeroTime(t *testing.T) { 30 now := time.Now() 31 zero := time.Time{} 32 33 got := TimeAtOrIn(now, zero, 0) 34 35 assert.Equal(t, zero, got) 36 } 37 38 func TestIsExpiredAtOrInWithNonZeroTime(t *testing.T) { 39 now := time.Now() 40 within := 5 * time.Minute 41 at := now.Add(10 * time.Minute) 42 in := time.Duration(0) 43 44 expired, ok := IsExpiredAtOrIn(now, within, at, in) 45 46 assert.False(t, ok) 47 assert.Equal(t, at, expired) 48 } 49 50 func TestIsExpiredAtOrInWithNonZeroDuration(t *testing.T) { 51 now := time.Now() 52 within := 5 * time.Minute 53 at := time.Time{} 54 in := 10 * time.Minute 55 56 expired, ok := IsExpiredAtOrIn(now, within, at, in) 57 58 assert.Equal(t, now.Add(in), expired) 59 assert.False(t, ok) 60 } 61 62 func TestIsExpiredAtOrInWithNonZeroTimeExpired(t *testing.T) { 63 now := time.Now() 64 within := 5 * time.Minute 65 at := now.Add(3 * time.Minute) 66 in := time.Duration(0) 67 68 expired, ok := IsExpiredAtOrIn(now, within, at, in) 69 70 assert.True(t, ok) 71 assert.Equal(t, at, expired) 72 } 73 74 func TestIsExpiredAtOrInWithNonZeroDurationExpired(t *testing.T) { 75 now := time.Now() 76 within := 5 * time.Minute 77 at := time.Time{} 78 in := -10 * time.Minute 79 80 expired, ok := IsExpiredAtOrIn(now, within, at, in) 81 82 assert.Equal(t, now.Add(in), expired) 83 assert.True(t, ok) 84 } 85 86 func TestIsExpiredAtOrInWithAmbiguousTime(t *testing.T) { 87 now := time.Now() 88 within := 5 * time.Minute 89 at := now.Add(-10 * time.Minute) 90 in := 10 * time.Minute 91 92 expired, ok := IsExpiredAtOrIn(now, within, at, in) 93 94 assert.Equal(t, now.Add(in), expired) 95 assert.False(t, ok) 96 }