Skip to content

Commit

Permalink
Test getNext
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed Mar 12, 2019
1 parent 0435228 commit f6a5536
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions dkron/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func (j *Job) Unlock() error {
return nil
}

// GetNext returns the job's next schedule
func (j *Job) GetNext() (time.Time, error) {
s, err := cron.Parse(j.Schedule)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions dkron/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dkron

import (
"testing"
"time"

s "github.com/abronan/valkeyrie/store"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -66,3 +67,16 @@ func TestJobGetParent(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, []string{}, ptj.DependentJobs)
}

func TestJobGetNext(t *testing.T) {
j := Job{
Schedule: "@daily",
}

td := time.Now()
tonight := time.Date(td.Year(), td.Month(), td.Day()+1, 0, 0, 0, 0, td.Location())
n, err := j.GetNext()

assert.NoError(t, err)
assert.Equal(t, tonight, n)
}

0 comments on commit f6a5536

Please sign in to comment.