mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
fix: gcron check if the predefined patterns fail (#2288)
This commit is contained in:
@ -123,8 +123,9 @@ func newSchedule(pattern string) (*cronSchedule, error) {
|
||||
pattern: pattern,
|
||||
lastTimestamp: gtype.NewInt64(currentTimestamp),
|
||||
}, nil
|
||||
} else {
|
||||
return nil, gerror.NewCodef(gcode.CodeInvalidParameter, `invalid pattern: "%s"`, pattern)
|
||||
}
|
||||
return nil, gerror.NewCodef(gcode.CodeInvalidParameter, `invalid pattern: "%s"`, pattern)
|
||||
}
|
||||
// Handle the common cron pattern, like:
|
||||
// 0 0 0 1 1 2
|
||||
|
||||
@ -73,6 +73,15 @@ func TestNext(t *testing.T) {
|
||||
|
||||
// Leap year
|
||||
{"Mon Jul 9 23:35 2012", "0 0 0 29 Feb ?", "Mon Feb 29 00:00 2016"},
|
||||
|
||||
// Predefined pattern map.
|
||||
{"Mon Jul 9 23:35 2012", "@yearly", "Sun Jan 1 00:00:00 2013"},
|
||||
{"Mon Jul 9 23:35 2012", "@annually", "Sun Jan 1 00:00:00 2013"},
|
||||
{"Mon Jul 9 23:35 2012", "@monthly", "Mon Aug 1 00:00:00 2012"},
|
||||
{"Mon Jul 9 23:35 2012", "@weekly", "Sun Jul 15 00:00:00 2012"},
|
||||
{"Mon Jul 9 23:35 2012", "@daily", "Tue Jul 10 00:00:00 2012"},
|
||||
{"Mon Jul 9 23:35 2012", "@midnight", "Tue Jul 10 00:00:00 2012"},
|
||||
{"Mon Jul 9 23:35 2012", "@hourly", "Tue Jul 10 00:00:00 2012"},
|
||||
}
|
||||
|
||||
for _, c := range runs {
|
||||
|
||||
@ -67,6 +67,22 @@ func TestCron_Basic(t *testing.T) {
|
||||
t.AssertNE(entry1, nil)
|
||||
t.Assert(entry2, nil)
|
||||
})
|
||||
|
||||
// test @ error
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
cron := gcron.New()
|
||||
defer cron.Close()
|
||||
_, err := cron.Add(ctx, "@aaa", func(ctx context.Context) {}, "add")
|
||||
t.AssertNE(err, nil)
|
||||
})
|
||||
|
||||
// test @every error
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
cron := gcron.New()
|
||||
defer cron.Close()
|
||||
_, err := cron.Add(ctx, "@every xxx", func(ctx context.Context) {}, "add")
|
||||
t.AssertNE(err, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCron_Remove(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user