(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestActivation(t *testing.T) { |
| 10 | tests := []struct { |
| 11 | time, spec string |
| 12 | expected bool |
| 13 | }{ |
| 14 | // Every fifteen minutes. |
| 15 | {"Mon Jul 9 15:00 2012", "0/15 * * * *", true}, |
| 16 | {"Mon Jul 9 15:45 2012", "0/15 * * * *", true}, |
| 17 | {"Mon Jul 9 15:40 2012", "0/15 * * * *", false}, |
| 18 | |
| 19 | // Every fifteen minutes, starting at 5 minutes. |
| 20 | {"Mon Jul 9 15:05 2012", "5/15 * * * *", true}, |
| 21 | {"Mon Jul 9 15:20 2012", "5/15 * * * *", true}, |
| 22 | {"Mon Jul 9 15:50 2012", "5/15 * * * *", true}, |
| 23 | |
| 24 | // Named months |
| 25 | {"Sun Jul 15 15:00 2012", "0/15 * * Jul *", true}, |
| 26 | {"Sun Jul 15 15:00 2012", "0/15 * * Jun *", false}, |
| 27 | |
| 28 | // Everything set. |
| 29 | {"Sun Jul 15 08:30 2012", "30 08 ? Jul Sun", true}, |
| 30 | {"Sun Jul 15 08:30 2012", "30 08 15 Jul ?", true}, |
| 31 | {"Mon Jul 16 08:30 2012", "30 08 ? Jul Sun", false}, |
| 32 | {"Mon Jul 16 08:30 2012", "30 08 15 Jul ?", false}, |
| 33 | |
| 34 | // Predefined schedules |
| 35 | {"Mon Jul 9 15:00 2012", "@hourly", true}, |
| 36 | {"Mon Jul 9 15:04 2012", "@hourly", false}, |
| 37 | {"Mon Jul 9 15:00 2012", "@daily", false}, |
| 38 | {"Mon Jul 9 00:00 2012", "@daily", true}, |
| 39 | {"Mon Jul 9 00:00 2012", "@weekly", false}, |
| 40 | {"Sun Jul 8 00:00 2012", "@weekly", true}, |
| 41 | {"Sun Jul 8 01:00 2012", "@weekly", false}, |
| 42 | {"Sun Jul 8 00:00 2012", "@monthly", false}, |
| 43 | {"Sun Jul 1 00:00 2012", "@monthly", true}, |
| 44 | |
| 45 | // Test interaction of DOW and DOM. |
| 46 | // If both are restricted, then only one needs to match. |
| 47 | {"Sun Jul 15 00:00 2012", "* * 1,15 * Sun", true}, |
| 48 | {"Fri Jun 15 00:00 2012", "* * 1,15 * Sun", true}, |
| 49 | {"Wed Aug 1 00:00 2012", "* * 1,15 * Sun", true}, |
| 50 | {"Sun Jul 15 00:00 2012", "* * */10 * Sun", true}, // verifies #70 |
| 51 | |
| 52 | // However, if one has a star, then both need to match. |
| 53 | {"Sun Jul 15 00:00 2012", "* * * * Mon", false}, |
| 54 | {"Mon Jul 9 00:00 2012", "* * 1,15 * *", false}, |
| 55 | {"Sun Jul 15 00:00 2012", "* * 1,15 * *", true}, |
| 56 | {"Sun Jul 15 00:00 2012", "* * */2 * Sun", true}, |
| 57 | } |
| 58 | |
| 59 | for _, test := range tests { |
| 60 | sched, err := ParseStandard(test.spec) |
| 61 | if err != nil { |
| 62 | t.Error(err) |
| 63 | continue |
| 64 | } |
| 65 | actual := sched.Next(getTime(test.time).Add(-1 * time.Second)) |
| 66 | expected := getTime(test.time) |
nothing calls this directly
no test coverage detected
searching dependent graphs…