whenever 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +0 -5
- data/README.md +3 -1
- data/lib/whenever.rb +10 -11
- data/lib/whenever/capistrano/v3/tasks/whenever.rake +2 -2
- data/lib/whenever/command_line.rb +9 -9
- data/lib/whenever/cron.rb +11 -11
- data/lib/whenever/job.rb +2 -2
- data/lib/whenever/job_list.rb +18 -7
- data/lib/whenever/numeric_seconds.rb +54 -0
- data/lib/whenever/tasks/whenever.rake +2 -2
- data/lib/whenever/version.rb +1 -1
- data/test/functional/command_line_test.rb +221 -224
- data/test/functional/output_at_test.rb +188 -249
- data/test/functional/output_default_defined_jobs_test.rb +214 -290
- data/test/functional/output_defined_job_test.rb +65 -91
- data/test/functional/output_env_test.rb +22 -26
- data/test/functional/output_jobs_for_roles_test.rb +46 -66
- data/test/functional/output_redirection_test.rb +231 -309
- data/test/test_case.rb +39 -0
- data/test/test_helper.rb +33 -14
- data/test/unit/capistrano_support_test.rb +126 -148
- data/test/unit/cron_test.rb +188 -215
- data/test/unit/job_test.rb +111 -121
- data/whenever.gemspec +0 -2
- metadata +15 -41
@@ -1,111 +1,85 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
|
-
class OutputDefinedJobTest <
|
3
|
+
class OutputDefinedJobTest < Whenever::TestCase
|
4
|
+
test "defined job with a :task" do
|
5
|
+
output = Whenever.cron \
|
6
|
+
<<-file
|
7
|
+
set :job_template, nil
|
8
|
+
job_type :some_job, "before :task after"
|
9
|
+
every 2.hours do
|
10
|
+
some_job "during"
|
11
|
+
end
|
12
|
+
file
|
4
13
|
|
5
|
-
|
6
|
-
setup do
|
7
|
-
@output = Whenever.cron \
|
8
|
-
<<-file
|
9
|
-
set :job_template, nil
|
10
|
-
job_type :some_job, "before :task after"
|
11
|
-
every 2.hours do
|
12
|
-
some_job "during"
|
13
|
-
end
|
14
|
-
file
|
15
|
-
end
|
16
|
-
|
17
|
-
should "output the defined job with the task" do
|
18
|
-
assert_match /^.+ .+ .+ .+ before during after$/, @output
|
19
|
-
end
|
14
|
+
assert_match /^.+ .+ .+ .+ before during after$/, output
|
20
15
|
end
|
21
16
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
file
|
32
|
-
end
|
17
|
+
test "defined job with a :task and some options" do
|
18
|
+
output = Whenever.cron \
|
19
|
+
<<-file
|
20
|
+
set :job_template, nil
|
21
|
+
job_type :some_job, "before :task after :option1 :option2"
|
22
|
+
every 2.hours do
|
23
|
+
some_job "during", :option1 => 'happy', :option2 => 'birthday'
|
24
|
+
end
|
25
|
+
file
|
33
26
|
|
34
|
-
|
35
|
-
assert_match /^.+ .+ .+ .+ before during after happy birthday$/, @output
|
36
|
-
end
|
27
|
+
assert_match /^.+ .+ .+ .+ before during after happy birthday$/, output
|
37
28
|
end
|
38
29
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
file
|
50
|
-
end
|
30
|
+
test "defined job with a :task and an option where the option is set globally" do
|
31
|
+
output = Whenever.cron \
|
32
|
+
<<-file
|
33
|
+
set :job_template, nil
|
34
|
+
job_type :some_job, "before :task after :option1"
|
35
|
+
set :option1, 'happy'
|
36
|
+
every 2.hours do
|
37
|
+
some_job "during"
|
38
|
+
end
|
39
|
+
file
|
51
40
|
|
52
|
-
|
53
|
-
assert_match /^.+ .+ .+ .+ before during after happy$/, @output
|
54
|
-
end
|
41
|
+
assert_match /^.+ .+ .+ .+ before during after happy$/, output
|
55
42
|
end
|
56
43
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
file
|
68
|
-
end
|
44
|
+
test "defined job with a :task and an option where the option is set globally and locally" do
|
45
|
+
output = Whenever.cron \
|
46
|
+
<<-file
|
47
|
+
set :job_template, nil
|
48
|
+
job_type :some_job, "before :task after :option1"
|
49
|
+
set :option1, 'global'
|
50
|
+
every 2.hours do
|
51
|
+
some_job "during", :option1 => 'local'
|
52
|
+
end
|
53
|
+
file
|
69
54
|
|
70
|
-
|
71
|
-
assert_match /^.+ .+ .+ .+ before during after local$/, @output
|
72
|
-
end
|
55
|
+
assert_match /^.+ .+ .+ .+ before during after local$/, output
|
73
56
|
end
|
74
57
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
file
|
85
|
-
end
|
58
|
+
test "defined job with a :task and an option that is not set" do
|
59
|
+
output = Whenever.cron \
|
60
|
+
<<-file
|
61
|
+
set :job_template, nil
|
62
|
+
job_type :some_job, "before :task after :option1"
|
63
|
+
every 2.hours do
|
64
|
+
some_job "during", :option2 => 'happy'
|
65
|
+
end
|
66
|
+
file
|
86
67
|
|
87
|
-
|
88
|
-
assert_match /^.+ .+ .+ .+ before during after :option1$/, @output
|
89
|
-
end
|
68
|
+
assert_match /^.+ .+ .+ .+ before during after :option1$/, output
|
90
69
|
end
|
91
70
|
|
92
|
-
|
93
|
-
|
94
|
-
Whenever.stubs(:path).returns('/my/path')
|
71
|
+
test "defined job that uses a :path where none is explicitly set" do
|
72
|
+
Whenever.stubs(:path).returns('/my/path')
|
95
73
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
74
|
+
output = Whenever.cron \
|
75
|
+
<<-file
|
76
|
+
set :job_template, nil
|
77
|
+
job_type :some_job, "cd :path && :task"
|
78
|
+
every 2.hours do
|
79
|
+
some_job 'blahblah'
|
80
|
+
end
|
81
|
+
file
|
105
82
|
|
106
|
-
|
107
|
-
assert_match two_hours + %( cd /my/path && blahblah), @output
|
108
|
-
end
|
83
|
+
assert_match two_hours + %( cd /my/path && blahblah), output
|
109
84
|
end
|
110
|
-
|
111
85
|
end
|
@@ -1,33 +1,29 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
|
-
class OutputEnvTest <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
file
|
14
|
-
end
|
3
|
+
class OutputEnvTest < Whenever::TestCase
|
4
|
+
setup do
|
5
|
+
@output = Whenever.cron \
|
6
|
+
<<-file
|
7
|
+
env :MYVAR, 'blah'
|
8
|
+
env 'MAILTO', "someone@example.com"
|
9
|
+
env :BLANKVAR, ''
|
10
|
+
env :NILVAR, nil
|
11
|
+
file
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
should "output MAILTO environment variable" do
|
21
|
-
assert_match "MAILTO=someone@example.com", @output
|
22
|
-
end
|
14
|
+
should "output MYVAR environment variable" do
|
15
|
+
assert_match "MYVAR=blah", @output
|
16
|
+
end
|
23
17
|
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
should "output MAILTO environment variable" do
|
19
|
+
assert_match "MAILTO=someone@example.com", @output
|
20
|
+
end
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
end
|
22
|
+
should "output BLANKVAR environment variable" do
|
23
|
+
assert_match "BLANKVAR=\"\"", @output
|
31
24
|
end
|
32
25
|
|
26
|
+
should "output NILVAR environment variable" do
|
27
|
+
assert_match "NILVAR=\"\"", @output
|
28
|
+
end
|
33
29
|
end
|
@@ -1,85 +1,65 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
|
-
class OutputJobsForRolesTest <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
file
|
12
|
-
end
|
3
|
+
class OutputJobsForRolesTest < Whenever::TestCase
|
4
|
+
test "one role requested and specified on the job" do
|
5
|
+
output = Whenever.cron :roles => [:role1], :string => \
|
6
|
+
<<-file
|
7
|
+
every 2.hours, :roles => [:role1] do
|
8
|
+
command "blahblah"
|
9
|
+
end
|
10
|
+
file
|
13
11
|
|
14
|
-
|
15
|
-
assert_equal two_hours + " /bin/bash -l -c 'blahblah'\n\n", @output
|
16
|
-
end
|
12
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'\n\n", output
|
17
13
|
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
file
|
27
|
-
end
|
15
|
+
test "one role requested but none specified on the job" do
|
16
|
+
output = Whenever.cron :roles => [:role1], :string => \
|
17
|
+
<<-file
|
18
|
+
every 2.hours do
|
19
|
+
command "blahblah"
|
20
|
+
end
|
21
|
+
file
|
28
22
|
|
29
23
|
# this should output the job because not specifying a role means "all roles"
|
30
|
-
|
31
|
-
assert_equal two_hours + " /bin/bash -l -c 'blahblah'\n\n", @output
|
32
|
-
end
|
24
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'\n\n", output
|
33
25
|
end
|
34
26
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
file
|
43
|
-
end
|
27
|
+
test "no roles requested but one specified on the job" do
|
28
|
+
output = Whenever.cron \
|
29
|
+
<<-file
|
30
|
+
every 2.hours, :roles => [:role1] do
|
31
|
+
command "blahblah"
|
32
|
+
end
|
33
|
+
file
|
44
34
|
|
45
35
|
# this should output the job because not requesting roles means "all roles"
|
46
|
-
|
47
|
-
assert_equal two_hours + " /bin/bash -l -c 'blahblah'\n\n", @output
|
48
|
-
end
|
36
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'\n\n", output
|
49
37
|
end
|
50
38
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
file
|
59
|
-
end
|
39
|
+
test "a different role requested than the one specified on the job" do
|
40
|
+
output = Whenever.cron :roles => [:role1], :string => \
|
41
|
+
<<-file
|
42
|
+
every 2.hours, :roles => [:role2] do
|
43
|
+
command "blahblah"
|
44
|
+
end
|
45
|
+
file
|
60
46
|
|
61
|
-
|
62
|
-
assert_equal "", @output
|
63
|
-
end
|
47
|
+
assert_equal "", output
|
64
48
|
end
|
65
49
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
50
|
+
test "with 2 roles requested and a job defined for each" do
|
51
|
+
output = Whenever.cron :roles => [:role1, :role2], :string => \
|
52
|
+
<<-file
|
53
|
+
every 2.hours, :roles => [:role1] do
|
54
|
+
command "role1_cmd"
|
55
|
+
end
|
73
56
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
57
|
+
every :hour, :roles => [:role2] do
|
58
|
+
command "role2_cmd"
|
59
|
+
end
|
60
|
+
file
|
79
61
|
|
80
|
-
|
81
|
-
|
82
|
-
assert_match "0 * * * * /bin/bash -l -c 'role2_cmd'", @output
|
83
|
-
end
|
62
|
+
assert_match two_hours + " /bin/bash -l -c 'role1_cmd'", output
|
63
|
+
assert_match "0 * * * * /bin/bash -l -c 'role2_cmd'", output
|
84
64
|
end
|
85
65
|
end
|
@@ -1,326 +1,248 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
class OutputRedirectionTest <
|
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OutputRedirectionTest < Whenever::TestCase
|
4
|
+
test "command when the output is set to nil" do
|
5
|
+
output = Whenever.cron \
|
6
|
+
<<-file
|
7
|
+
set :job_template, nil
|
8
|
+
set :output, nil
|
9
|
+
every 2.hours do
|
10
|
+
command "blahblah"
|
11
|
+
end
|
12
|
+
file
|
13
|
+
|
14
|
+
assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2>&1$/, output
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
test "command when the output is set" do
|
19
|
+
output = Whenever.cron \
|
20
|
+
<<-file
|
21
|
+
set :job_template, nil
|
22
|
+
set :output, 'logfile.log'
|
23
|
+
every 2.hours do
|
24
|
+
command "blahblah"
|
25
|
+
end
|
26
|
+
file
|
27
|
+
|
28
|
+
assert_match /^.+ .+ .+ .+ blahblah >> logfile.log 2>&1$/, output
|
29
|
+
end
|
30
|
+
|
31
|
+
test "command when the error and standard output is set by the command" do
|
32
|
+
output = Whenever.cron \
|
33
|
+
<<-file
|
34
|
+
set :job_template, nil
|
35
|
+
every 2.hours do
|
36
|
+
command "blahblah", :output => {:standard => 'dev_null', :error => 'dev_err'}
|
37
|
+
end
|
38
|
+
file
|
39
|
+
|
40
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, output
|
41
|
+
end
|
42
|
+
|
43
|
+
test "command when the output is set and the comand overrides it" do
|
44
|
+
output = Whenever.cron \
|
45
|
+
<<-file
|
46
|
+
set :job_template, nil
|
47
|
+
set :output, 'logfile.log'
|
48
|
+
every 2.hours do
|
49
|
+
command "blahblah", :output => 'otherlog.log'
|
50
|
+
end
|
51
|
+
file
|
52
|
+
|
53
|
+
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output
|
54
|
+
assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1$/, output
|
55
|
+
end
|
56
|
+
|
57
|
+
test "command when the output is set and the comand overrides with standard and error" do
|
58
|
+
output = Whenever.cron \
|
59
|
+
<<-file
|
60
|
+
set :job_template, nil
|
61
|
+
set :output, 'logfile.log'
|
62
|
+
every 2.hours do
|
63
|
+
command "blahblah", :output => {:error => 'dev_err', :standard => 'dev_null' }
|
64
|
+
end
|
65
|
+
file
|
66
|
+
|
67
|
+
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output
|
68
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, output
|
69
|
+
end
|
70
|
+
|
71
|
+
test "command when the output is set and the comand rejects it" do
|
72
|
+
output = Whenever.cron \
|
73
|
+
<<-file
|
74
|
+
set :job_template, nil
|
75
|
+
set :output, 'logfile.log'
|
76
|
+
every 2.hours do
|
77
|
+
command "blahblah", :output => false
|
78
|
+
end
|
79
|
+
file
|
80
|
+
|
81
|
+
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output
|
82
|
+
assert_match /^.+ .+ .+ .+ blahblah$/, output
|
83
|
+
end
|
84
|
+
|
85
|
+
test "command when the output is set and is overridden by the :set option" do
|
86
|
+
output = Whenever.cron :set => 'output=otherlog.log', :string => \
|
87
|
+
<<-file
|
88
|
+
set :job_template, nil
|
89
|
+
set :output, 'logfile.log'
|
90
|
+
every 2.hours do
|
91
|
+
command "blahblah"
|
92
|
+
end
|
93
|
+
file
|
94
|
+
|
95
|
+
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output
|
96
|
+
assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1/, output
|
97
|
+
end
|
98
|
+
|
99
|
+
test "command when the error and standard output is set" do
|
100
|
+
output = Whenever.cron \
|
101
|
+
<<-file
|
102
|
+
set :job_template, nil
|
103
|
+
set :output, {:error => 'dev_err', :standard => 'dev_null' }
|
104
|
+
every 2.hours do
|
105
|
+
command "blahblah"
|
106
|
+
end
|
107
|
+
file
|
108
|
+
|
109
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, output
|
110
|
+
end
|
111
|
+
|
112
|
+
test "command when error output is set" do
|
113
|
+
output = Whenever.cron \
|
114
|
+
<<-file
|
115
|
+
set :job_template, nil
|
116
|
+
set :output, {:error => 'dev_null'}
|
117
|
+
every 2.hours do
|
118
|
+
command "blahblah"
|
119
|
+
end
|
120
|
+
file
|
121
|
+
|
122
|
+
assert_match /^.+ .+ .+ .+ blahblah 2>> dev_null$/, output
|
123
|
+
end
|
124
|
+
|
125
|
+
test "command when the standard output is set" do
|
126
|
+
output = Whenever.cron \
|
127
|
+
<<-file
|
128
|
+
set :job_template, nil
|
129
|
+
set :output, {:standard => 'dev_out'}
|
130
|
+
every 2.hours do
|
131
|
+
command "blahblah"
|
132
|
+
end
|
133
|
+
file
|
134
|
+
|
135
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_out$/, output
|
136
|
+
end
|
137
|
+
|
138
|
+
test "command when error output is set by the command" do
|
139
|
+
output = Whenever.cron \
|
140
|
+
<<-file
|
141
|
+
set :job_template, nil
|
142
|
+
every 2.hours do
|
143
|
+
command "blahblah", :output => {:error => 'dev_err'}
|
144
|
+
end
|
145
|
+
file
|
146
|
+
|
147
|
+
assert_match /^.+ .+ .+ .+ blahblah 2>> dev_err$/, output
|
148
|
+
end
|
149
|
+
|
150
|
+
test "command when standard output is set by the command" do
|
151
|
+
output = Whenever.cron \
|
152
|
+
<<-file
|
153
|
+
set :job_template, nil
|
154
|
+
every 2.hours do
|
155
|
+
command "blahblah", :output => {:standard => 'dev_out'}
|
156
|
+
end
|
157
|
+
file
|
158
|
+
|
159
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_out$/, output
|
160
|
+
end
|
161
|
+
|
162
|
+
test "command when standard output is set to nil" do
|
163
|
+
output = Whenever.cron \
|
164
|
+
<<-file
|
165
|
+
set :job_template, nil
|
166
|
+
every 2.hours do
|
167
|
+
command "blahblah", :output => {:standard => nil}
|
168
|
+
end
|
169
|
+
file
|
170
|
+
|
171
|
+
assert_match /^.+ .+ .+ .+ blahblah > \/dev\/null$/, output
|
172
|
+
end
|
173
|
+
|
174
|
+
test "command when standard error is set to nil" do
|
175
|
+
output = Whenever.cron \
|
176
|
+
<<-file
|
177
|
+
set :job_template, nil
|
178
|
+
every 2.hours do
|
179
|
+
command "blahblah", :output => {:error => nil}
|
180
|
+
end
|
181
|
+
file
|
109
182
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
should "output the otherlog.log as the log file" do
|
123
|
-
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
124
|
-
assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1/, @output
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
context "A command when the error and standard output is set" do
|
129
|
-
setup do
|
130
|
-
@output = Whenever.cron \
|
131
|
-
<<-file
|
132
|
-
set :job_template, nil
|
133
|
-
set :output, {:error => 'dev_err', :standard => 'dev_null' }
|
134
|
-
every 2.hours do
|
135
|
-
command "blahblah"
|
136
|
-
end
|
137
|
-
file
|
138
|
-
end
|
139
|
-
|
140
|
-
should "output the command without the redirection syntax appended" do
|
141
|
-
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context "A command when error output is set" do
|
146
|
-
setup do
|
147
|
-
@output = Whenever.cron \
|
148
|
-
<<-file
|
149
|
-
set :job_template, nil
|
150
|
-
set :output, {:error => 'dev_null'}
|
151
|
-
every 2.hours do
|
152
|
-
command "blahblah"
|
153
|
-
end
|
154
|
-
file
|
155
|
-
end
|
156
|
-
|
157
|
-
should "output the command without the standard error syntax appended" do
|
158
|
-
assert_match /^.+ .+ .+ .+ blahblah 2>> dev_null$/, @output
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context "A command when the standard output is set" do
|
163
|
-
setup do
|
164
|
-
@output = Whenever.cron \
|
165
|
-
<<-file
|
166
|
-
set :job_template, nil
|
167
|
-
set :output, {:standard => 'dev_out'}
|
168
|
-
every 2.hours do
|
169
|
-
command "blahblah"
|
170
|
-
end
|
171
|
-
file
|
172
|
-
end
|
173
|
-
|
174
|
-
should "output the command with standard output syntax appended" do
|
175
|
-
assert_match /^.+ .+ .+ .+ blahblah >> dev_out$/, @output
|
176
|
-
end
|
177
|
-
end
|
183
|
+
assert_match /^.+ .+ .+ .+ blahblah 2> \/dev\/null$/, output
|
184
|
+
end
|
185
|
+
|
186
|
+
test "command when standard output and standard error is set to nil" do
|
187
|
+
output = Whenever.cron \
|
188
|
+
<<-file
|
189
|
+
set :job_template, nil
|
190
|
+
every 2.hours do
|
191
|
+
command "blahblah", :output => {:error => nil, :standard => nil}
|
192
|
+
end
|
193
|
+
file
|
178
194
|
|
179
|
-
|
180
|
-
setup do
|
181
|
-
@output = Whenever.cron \
|
182
|
-
<<-file
|
183
|
-
set :job_template, nil
|
184
|
-
every 2.hours do
|
185
|
-
command "blahblah", :output => {:error => 'dev_err'}
|
186
|
-
end
|
187
|
-
file
|
188
|
-
end
|
189
|
-
|
190
|
-
should "output the command without the log syntax appended" do
|
191
|
-
assert_match /^.+ .+ .+ .+ blahblah 2>> dev_err$/, @output
|
192
|
-
end
|
195
|
+
assert_match /^.+ .+ .+ .+ blahblah > \/dev\/null 2>&1$/, output
|
193
196
|
end
|
194
197
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
file
|
204
|
-
end
|
205
|
-
|
206
|
-
should "output the command without the log syntax appended" do
|
207
|
-
assert_match /^.+ .+ .+ .+ blahblah >> dev_out$/, @output
|
208
|
-
end
|
209
|
-
end
|
198
|
+
test "command when standard output is set and standard error is set to nil" do
|
199
|
+
output = Whenever.cron \
|
200
|
+
<<-file
|
201
|
+
set :job_template, nil
|
202
|
+
every 2.hours do
|
203
|
+
command "blahblah", :output => {:error => nil, :standard => 'my.log'}
|
204
|
+
end
|
205
|
+
file
|
210
206
|
|
211
|
-
|
212
|
-
setup do
|
213
|
-
@output = Whenever.cron \
|
214
|
-
<<-file
|
215
|
-
set :job_template, nil
|
216
|
-
every 2.hours do
|
217
|
-
command "blahblah", :output => {:standard => nil}
|
218
|
-
end
|
219
|
-
file
|
220
|
-
end
|
221
|
-
|
222
|
-
should "output the command with stdout directed to /dev/null" do
|
223
|
-
assert_match /^.+ .+ .+ .+ blahblah > \/dev\/null$/, @output
|
224
|
-
end
|
207
|
+
assert_match /^.+ .+ .+ .+ blahblah >> my.log 2> \/dev\/null$/, output
|
225
208
|
end
|
226
209
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
file
|
236
|
-
end
|
237
|
-
|
238
|
-
should "output the command with stderr directed to /dev/null" do
|
239
|
-
assert_match /^.+ .+ .+ .+ blahblah 2> \/dev\/null$/, @output
|
240
|
-
end
|
241
|
-
end
|
210
|
+
test "command when standard output is nil and standard error is set" do
|
211
|
+
output = Whenever.cron \
|
212
|
+
<<-file
|
213
|
+
set :job_template, nil
|
214
|
+
every 2.hours do
|
215
|
+
command "blahblah", :output => {:error => 'my_error.log', :standard => nil}
|
216
|
+
end
|
217
|
+
file
|
242
218
|
|
243
|
-
|
244
|
-
setup do
|
245
|
-
@output = Whenever.cron \
|
246
|
-
<<-file
|
247
|
-
set :job_template, nil
|
248
|
-
every 2.hours do
|
249
|
-
command "blahblah", :output => {:error => nil, :standard => nil}
|
250
|
-
end
|
251
|
-
file
|
252
|
-
end
|
253
|
-
|
254
|
-
should "output the command with stderr directed to /dev/null" do
|
255
|
-
assert_match /^.+ .+ .+ .+ blahblah > \/dev\/null 2>&1$/, @output
|
256
|
-
end
|
219
|
+
assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2>> my_error.log$/, output
|
257
220
|
end
|
258
221
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
end
|
269
|
-
|
270
|
-
should "output the command with stderr directed to /dev/null" do
|
271
|
-
assert_match /^.+ .+ .+ .+ blahblah >> my.log 2> \/dev\/null$/, @output
|
272
|
-
end
|
273
|
-
end
|
222
|
+
test "command when the deprecated :cron_log is set" do
|
223
|
+
output = Whenever.cron \
|
224
|
+
<<-file
|
225
|
+
set :job_template, nil
|
226
|
+
set :cron_log, "cron.log"
|
227
|
+
every 2.hours do
|
228
|
+
command "blahblah"
|
229
|
+
end
|
230
|
+
file
|
274
231
|
|
275
|
-
|
276
|
-
setup do
|
277
|
-
@output = Whenever.cron \
|
278
|
-
<<-file
|
279
|
-
set :job_template, nil
|
280
|
-
every 2.hours do
|
281
|
-
command "blahblah", :output => {:error => 'my_error.log', :standard => nil}
|
282
|
-
end
|
283
|
-
file
|
284
|
-
end
|
285
|
-
|
286
|
-
should "output the command with stderr directed to /dev/null" do
|
287
|
-
assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2>> my_error.log$/, @output
|
288
|
-
end
|
232
|
+
assert_match /^.+ .+ .+ .+ blahblah >> cron.log 2>&1$/, output
|
289
233
|
end
|
290
234
|
|
291
|
-
context "A command when the deprecated :cron_log is set" do
|
292
|
-
setup do
|
293
|
-
@output = Whenever.cron \
|
294
|
-
<<-file
|
295
|
-
set :job_template, nil
|
296
|
-
set :cron_log, "cron.log"
|
297
|
-
every 2.hours do
|
298
|
-
command "blahblah"
|
299
|
-
end
|
300
|
-
file
|
301
|
-
end
|
302
|
-
|
303
|
-
should "output the command with with the stdout and stderr going to the log" do
|
304
|
-
assert_match /^.+ .+ .+ .+ blahblah >> cron.log 2>&1$/, @output
|
305
|
-
end
|
306
|
-
end
|
307
235
|
|
236
|
+
test "a command when the standard output is set to a lambda" do
|
237
|
+
output = Whenever.cron \
|
238
|
+
<<-file
|
239
|
+
set :job_template, nil
|
240
|
+
set :output, lambda { "2>&1 | logger -t whenever_cron" }
|
241
|
+
every 2.hours do
|
242
|
+
command "blahblah"
|
243
|
+
end
|
244
|
+
file
|
308
245
|
|
309
|
-
|
310
|
-
setup do
|
311
|
-
@output = Whenever.cron \
|
312
|
-
<<-file
|
313
|
-
set :job_template, nil
|
314
|
-
set :output, lambda { "2>&1 | logger -t whenever_cron" }
|
315
|
-
every 2.hours do
|
316
|
-
command "blahblah"
|
317
|
-
end
|
318
|
-
file
|
319
|
-
end
|
320
|
-
|
321
|
-
should "output the command by result of the lambda evaluated" do
|
322
|
-
assert_match /^.+ .+ .+ .+ blahblah 2>&1 | logger -t whenever_cron$/, @output
|
323
|
-
end
|
246
|
+
assert_match /^.+ .+ .+ .+ blahblah 2>&1 | logger -t whenever_cron$/, output
|
324
247
|
end
|
325
|
-
|
326
248
|
end
|