-
Notifications
You must be signed in to change notification settings - Fork 1
/
schtasks_test.go
81 lines (66 loc) · 1.95 KB
/
schtasks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package schtasks
import (
"fmt"
"github.com/stretchr/testify/require"
"testing"
"time"
)
// TestRunEveryMinutes also tests Get and ForceDelete
func TestRunEveryMinutes(t *testing.T) {
// Create the task
taskName := t.Name()
_, err := RunEveryMinutes(taskName, 1, "dir")
require.NoError(t, err)
// Get task to verify it was created
st, err := Get(taskName)
require.NoError(t, err)
require.Contains(t, st.TaskName, taskName)
// Delete the task
_, err = ForceDelete(taskName)
require.NoError(t, err)
// Get task to verify it was deleted
st, err = Get(taskName)
require.Error(t, err)
require.Contains(t, err.Error(), fmt.Sprintf("task %s not found", taskName))
}
func TestTimeAtMinutes(t *testing.T) {
t1Str := "2006-01-02T15:04:50Z"
t2Str := "2006-01-02T15:04:55Z"
t3Str := "2006-01-02T23:59:56Z"
t1, err := time.Parse(time.RFC3339, t1Str)
require.NoError(t, err)
t2, err := time.Parse(time.RFC3339, t2Str)
require.NoError(t, err)
t3, err := time.Parse(time.RFC3339, t3Str)
require.NoError(t, err)
timeAt := TimeAtMinutes(t1, 1)
require.Equal(t, "15:05", timeAt)
timeAt = TimeAtMinutes(t1, 2)
require.Equal(t, "15:06", timeAt)
// Assuming PaddingSeconds = 5
timeAt = TimeAtMinutes(t2, 1)
require.Equal(t, "15:06", timeAt)
timeAt = TimeAtMinutes(t2, 2)
require.Equal(t, "15:07", timeAt)
timeAt = TimeAtMinutes(t3, 1)
require.Equal(t, "00:01", timeAt)
timeAt = TimeAtMinutes(t3, 2)
require.Equal(t, "00:02", timeAt)
}
func TestRunAtMinutes(t *testing.T) {
// Create the task
taskName := t.Name()
_, err := RunAtMinutes(taskName, 1, "dir")
require.NoError(t, err)
// Get task to verify it was created
st, err := Get(taskName)
require.NoError(t, err)
require.Contains(t, st.TaskName, taskName)
// Delete the task
_, err = ForceDelete(taskName)
require.NoError(t, err)
// Get task to verify it was deleted
st, err = Get(taskName)
require.Error(t, err)
require.Contains(t, err.Error(), fmt.Sprintf("task %s not found", taskName))
}