Dump changes

This commit is contained in:
Andrey Chervyakov 2022-06-03 23:44:08 +06:00
parent e12550a643
commit aac2ea1b74
Signed by: cognio
GPG key ID: DAA316147EB0D58D
25 changed files with 129 additions and 76 deletions

View file

@ -1,62 +0,0 @@
package scheduling
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestNextTime(t *testing.T) {
pattern := Pattern("0 * * * *")
now := time.Now()
nextTime, _ := pattern.NextTime(now)
assert.True(t, now.Add(time.Hour).Truncate(time.Hour).Equal(*nextTime))
}
func TestNextTimeUntil(t *testing.T) {
pattern := Pattern("0 0 * * *")
now := time.Now()
nextTimes, _ := pattern.NextTimesUntil(now, now.Add(5*24*time.Hour))
assert.True(t, len(nextTimes) == 5)
}
func TestMatchesTime(t *testing.T) {
testCases := []struct {
pattern Pattern
expected time.Time
precision time.Duration
}{
{
pattern: Pattern("0 * * * *"),
expected: time.Now().Add(time.Hour).Truncate(time.Hour),
precision: time.Hour,
},
{
pattern: Pattern("5 4 * * *"),
expected: time.Now().Add(24 * time.Hour),
precision: 24 * time.Hour,
},
}
for _, testCase := range testCases {
matchingTime, _ := testCase.pattern.MatchesTime(testCase.expected, testCase.precision)
assert.NotNil(t, matchingTime)
}
}
func TestNotMatchesTime(t *testing.T) {
pattern := Pattern("0 * * * *")
nextHour := time.Now().Add(time.Hour + 30*time.Minute)
matchingTime, _ := pattern.MatchesTime(nextHour, time.Minute)
assert.Nil(t, matchingTime)
}