Add existing codebase
This commit is contained in:
commit
e12550a643
25 changed files with 1409 additions and 0 deletions
62
pkg/brainbuffer/scheduling/pattern_test.go
Normal file
62
pkg/brainbuffer/scheduling/pattern_test.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue