Merge branch 'b-cron-parse' of github.com:hashicorp/nomad into b-cron-parse

This commit is contained in:
Alex Dadgar 2018-04-26 15:51:56 -07:00
commit 05eccb063f
1 changed files with 40 additions and 19 deletions

View File

@ -2009,18 +2009,44 @@ func TestPeriodicConfig_ValidCron(t *testing.T) {
}
func TestPeriodicConfig_NextCron(t *testing.T) {
require := require.New(t)
type testExpectation struct {
Time time.Time
HasError bool
ErrorMsg string
}
from := time.Date(2009, time.November, 10, 23, 22, 30, 0, time.UTC)
specs := []string{"0 0 29 2 * 1980", "*/5 * * * *"}
expected := []time.Time{{}, time.Date(2009, time.November, 10, 23, 25, 0, 0, time.UTC)}
specs := []string{"0 0 29 2 * 1980",
"*/5 * * * *",
"1 15-0 * * 1-5"}
expected := []*testExpectation{
{
Time: time.Time{},
HasError: false,
},
{
Time: time.Date(2009, time.November, 10, 23, 25, 0, 0, time.UTC),
HasError: false,
},
{
Time: time.Time{},
HasError: true,
ErrorMsg: "failed parsing cron expression",
},
}
for i, spec := range specs {
p := &PeriodicConfig{Enabled: true, SpecType: PeriodicSpecCron, Spec: spec}
p.Canonicalize()
n, err := p.Next(from)
nextExpected := expected[i]
require.Equal(nextExpected.Time, n)
require.Equal(err != nil, nextExpected.HasError)
if err != nil {
t.Fatalf("Next returned error: %v", err)
}
if expected[i] != n {
t.Fatalf("Next(%v) returned %v; want %v", from, n, expected[i])
require.True(strings.Contains(err.Error(), nextExpected.ErrorMsg))
}
}
}
@ -2037,6 +2063,8 @@ func TestPeriodicConfig_ValidTimeZone(t *testing.T) {
}
func TestPeriodicConfig_DST(t *testing.T) {
require := require.New(t)
// On Sun, Mar 12, 2:00 am 2017: +1 hour UTC
p := &PeriodicConfig{
Enabled: true,
@ -2053,21 +2081,14 @@ func TestPeriodicConfig_DST(t *testing.T) {
e1 := time.Date(2017, time.March, 11, 10, 0, 0, 0, time.UTC)
e2 := time.Date(2017, time.March, 12, 9, 0, 0, 0, time.UTC)
n1, err1 := p.Next(t1)
n2, err2 := p.Next(t2)
if err1 != nil || err2 != nil {
t.Fatalf("bad: %v %v", err1, err2)
}
n1, err := p.Next(t1)
require.Nil(err)
n1 = n1.UTC()
n2 = n2.UTC()
n2, err := p.Next(t2)
require.Nil(err)
if !reflect.DeepEqual(e1, n1) {
t.Fatalf("Got %v; want %v", n1, e1)
}
if !reflect.DeepEqual(e2, n2) {
t.Fatalf("Got %v; want %v", n1, e1)
}
require.Equal(e1, n1.UTC())
require.Equal(e2, n2.UTC())
}
func TestRestartPolicy_Validate(t *testing.T) {