From f6a55360c60ffcfc5997fd6b0187d0e5982917a8 Mon Sep 17 00:00:00 2001 From: Victor Castell Date: Tue, 12 Mar 2019 22:02:06 +0100 Subject: [PATCH] Test getNext --- dkron/job.go | 1 + dkron/job_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/dkron/job.go b/dkron/job.go index 3407ee7df..6c2bad758 100644 --- a/dkron/job.go +++ b/dkron/job.go @@ -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 { diff --git a/dkron/job_test.go b/dkron/job_test.go index 365a377e6..3ac8506cb 100644 --- a/dkron/job_test.go +++ b/dkron/job_test.go @@ -2,6 +2,7 @@ package dkron import ( "testing" + "time" s "github.com/abronan/valkeyrie/store" "github.com/stretchr/testify/assert" @@ -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) +}