forked from creativeprojects/resticprofile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule_jobs_test.go
98 lines (87 loc) · 3.19 KB
/
schedule_jobs_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"testing"
"github.com/creativeprojects/resticprofile/calendar"
"github.com/creativeprojects/resticprofile/config"
"github.com/creativeprojects/resticprofile/mocks"
"github.com/creativeprojects/resticprofile/platform"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestScheduleNilJobs(t *testing.T) {
handler := mocks.NewHandler(t)
handler.On("Init").Return(nil)
handler.On("Close")
err := scheduleJobs(handler, "profile", nil)
assert.NoError(t, err)
}
func TestArgumentsOnScheduleJobNoLog(t *testing.T) {
handler := getMockHandler(t)
handler.On("CreateJob",
mock.AnythingOfType("*config.ScheduleConfig"),
mock.AnythingOfType("[]*calendar.Event"),
mock.AnythingOfType("string")).
Return(func(scheduleConfig *config.ScheduleConfig, events []*calendar.Event, permission string) error {
assert.Equal(t, []string{"--no-ansi", "--config", "", "--name", "profile", "backup"}, scheduleConfig.Arguments)
return nil
})
scheduleConfig := &config.ScheduleConfig{
Title: "profile",
SubTitle: "backup",
}
err := scheduleJobs(handler, "profile", []*config.ScheduleConfig{scheduleConfig})
assert.NoError(t, err)
}
func TestArgumentsOnScheduleJobLogFile(t *testing.T) {
handler := getMockHandler(t)
handler.On("CreateJob",
mock.AnythingOfType("*config.ScheduleConfig"),
mock.AnythingOfType("[]*calendar.Event"),
mock.AnythingOfType("string")).
Return(func(scheduleConfig *config.ScheduleConfig, events []*calendar.Event, permission string) error {
if platform.IsDarwin() {
// on mac os, we use the launchd output redirection
assert.Equal(t, []string{"--no-ansi", "--config", "", "--name", "profile", "backup"}, scheduleConfig.Arguments)
} else {
assert.Equal(t, []string{"--no-ansi", "--config", "", "--name", "profile", "--log", "/path/to/file", "backup"}, scheduleConfig.Arguments)
}
return nil
})
scheduleConfig := &config.ScheduleConfig{
Title: "profile",
SubTitle: "backup",
Log: "/path/to/file",
}
err := scheduleJobs(handler, "profile", []*config.ScheduleConfig{scheduleConfig})
assert.NoError(t, err)
}
func TestArgumentsOnScheduleJobLogSyslog(t *testing.T) {
if !platform.SupportsSyslog() {
t.Skip("syslog is not supported")
}
handler := getMockHandler(t)
handler.On("CreateJob",
mock.AnythingOfType("*config.ScheduleConfig"),
mock.AnythingOfType("[]*calendar.Event"),
mock.AnythingOfType("string")).
Return(func(scheduleConfig *config.ScheduleConfig, events []*calendar.Event, permission string) error {
assert.Equal(t, []string{"--no-ansi", "--config", "", "--name", "profile", "--log", "tcp://localhost:123", "backup"}, scheduleConfig.Arguments)
return nil
})
scheduleConfig := &config.ScheduleConfig{
Title: "profile",
SubTitle: "backup",
Log: "tcp://localhost:123",
}
err := scheduleJobs(handler, "profile", []*config.ScheduleConfig{scheduleConfig})
assert.NoError(t, err)
}
func getMockHandler(t *testing.T) *mocks.Handler {
t.Helper()
handler := mocks.NewHandler(t)
handler.On("Init").Return(nil)
handler.On("Close")
handler.On("ParseSchedules", []string(nil)).Return(nil, nil)
handler.On("DisplaySchedules", "backup", []string(nil)).Return(nil)
return handler
}