whenever 0.8.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +20 -7
- data/Appraisals +19 -0
- data/CHANGELOG.md +116 -3
- data/Gemfile +3 -3
- data/LICENSE +2 -2
- data/README.md +133 -32
- data/Rakefile +3 -10
- data/bin/whenever +3 -0
- data/bin/wheneverize +8 -5
- data/gemfiles/activesupport4.1.gemfile +7 -0
- data/gemfiles/activesupport4.2.gemfile +7 -0
- data/gemfiles/activesupport5.0.gemfile +7 -0
- data/gemfiles/activesupport5.1.gemfile +7 -0
- data/gemfiles/activesupport5.2.gemfile +7 -0
- data/lib/whenever/capistrano/v2/hooks.rb +8 -0
- data/lib/whenever/capistrano/{recipes.rb → v2/recipes.rb} +7 -13
- data/lib/whenever/capistrano/{support.rb → v2/support.rb} +12 -0
- data/lib/whenever/capistrano/v3/tasks/whenever.rake +56 -0
- data/lib/whenever/capistrano.rb +5 -6
- data/lib/whenever/command_line.rb +69 -48
- data/lib/whenever/cron.rb +54 -25
- data/lib/whenever/job.rb +13 -14
- data/lib/whenever/job_list.rb +54 -24
- data/lib/whenever/numeric.rb +13 -0
- data/lib/whenever/numeric_seconds.rb +48 -0
- data/lib/whenever/os.rb +7 -0
- data/lib/whenever/output_redirection.rb +1 -0
- data/lib/whenever/setup.rb +19 -15
- data/lib/whenever/version.rb +2 -2
- data/lib/whenever.rb +19 -14
- data/test/functional/command_line_test.rb +379 -243
- data/test/functional/output_at_test.rb +227 -249
- data/test/functional/output_default_defined_jobs_test.rb +251 -193
- 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 -65
- data/test/functional/output_jobs_with_mailto_test.rb +168 -0
- data/test/functional/output_redirection_test.rb +232 -291
- data/test/test_case.rb +32 -0
- data/test/test_helper.rb +44 -15
- data/test/unit/capistrano_support_test.rb +128 -134
- data/test/unit/cron_test.rb +373 -208
- data/test/unit/executable_test.rb +142 -0
- data/test/unit/job_test.rb +111 -117
- data/whenever.gemspec +7 -4
- metadata +63 -44
@@ -1,153 +1,147 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'test_helper'
|
2
|
+
require 'whenever/capistrano/v2/support'
|
3
3
|
|
4
4
|
class CapistranoSupportTestSubject
|
5
5
|
include Whenever::CapistranoSupport
|
6
6
|
end
|
7
7
|
|
8
|
-
class
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
class CapistranoTestCase < Whenever::TestCase
|
9
|
+
setup do
|
10
|
+
@capistrano = CapistranoSupportTestSubject.new
|
11
|
+
configuration = mock()
|
12
|
+
configuration.stubs(:load).yields(@capistrano)
|
13
|
+
Whenever::CapistranoSupport.load_into(configuration)
|
14
|
+
end
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
17
|
+
class CapistranoSupportTest < CapistranoTestCase
|
18
|
+
should "return fetch(:whenever_options) from #whenever_options" do
|
19
|
+
@capistrano.expects(:fetch).with(:whenever_options)
|
20
|
+
@capistrano.whenever_options
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
should "return whenever_options[:roles] as an array from #whenever_roles with one role" do
|
24
|
+
@capistrano.stubs(:whenever_options).returns({:roles => :role1})
|
25
|
+
assert_equal [:role1], @capistrano.whenever_roles
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
should "return an empty array from #whenever_roles with no defined roles" do
|
29
|
+
@capistrano.stubs(:whenever_options).returns({})
|
30
|
+
assert_equal [], @capistrano.whenever_roles
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
33
|
+
should "return the list of servers returned by find_servers from #whenever_servers" do
|
34
|
+
@capistrano.stubs(:whenever_options).returns({})
|
35
|
+
@capistrano.stubs(:find_servers).returns([:server1, :server2])
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
37
|
+
assert_equal [:server1, :server2], @capistrano.whenever_servers
|
38
|
+
end
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
should "#whenever_prepare_for_rollback: set path to previous_release if there is a previous release" do
|
41
|
+
args = {}
|
42
|
+
@capistrano.stubs(:fetch).with(:previous_release).returns("/some/path/20121221010000")
|
43
|
+
assert_equal({:path => "/some/path/20121221010000"}, @capistrano.whenever_prepare_for_rollback(args))
|
44
|
+
end
|
45
|
+
|
46
|
+
should "#whenever_prepare_for_rollback: set path to release_path and flags to whenever_clear_flags if there is no previous release" do
|
47
|
+
args = {}
|
48
|
+
@capistrano.stubs(:fetch).with(:previous_release).returns(nil)
|
49
|
+
@capistrano.stubs(:fetch).with(:release_path).returns("/some/path/20121221010000")
|
50
|
+
@capistrano.stubs(:fetch).with(:whenever_clear_flags).returns("--clear-crontab whenever_identifier")
|
51
|
+
assert_equal({:path => "/some/path/20121221010000", :flags => "--clear-crontab whenever_identifier"}, @capistrano.whenever_prepare_for_rollback(args))
|
52
|
+
end
|
48
53
|
|
49
|
-
|
50
|
-
|
54
|
+
should "#whenever_run_commands: require :command arg" do
|
55
|
+
assert_raises ArgumentError do
|
56
|
+
@capistrano.whenever_run_commands(:options => {}, :path => {}, :flags => {})
|
51
57
|
end
|
58
|
+
end
|
52
59
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
@capistrano.stubs(:whenever_servers).returns(@mock_servers)
|
57
|
-
end
|
58
|
-
|
59
|
-
should "return a map of servers to their role(s)" do
|
60
|
-
@capistrano.stubs(:whenever_roles).returns([:role1, :role2])
|
61
|
-
@capistrano.stubs(:role_names_for_host).with("foo").returns([:role1])
|
62
|
-
@capistrano.stubs(:role_names_for_host).with("bar").returns([:role2])
|
63
|
-
assert_equal({"foo" => [:role1], "bar" => [:role2]}, @capistrano.whenever_server_roles)
|
64
|
-
end
|
65
|
-
|
66
|
-
should "exclude non-requested roles" do
|
67
|
-
@capistrano.stubs(:whenever_roles).returns([:role1, :role2])
|
68
|
-
@capistrano.stubs(:role_names_for_host).with("foo").returns([:role1, :role3])
|
69
|
-
@capistrano.stubs(:role_names_for_host).with("bar").returns([:role2])
|
70
|
-
assert_equal({"foo" => [:role1], "bar" => [:role2]}, @capistrano.whenever_server_roles)
|
71
|
-
end
|
72
|
-
|
73
|
-
should "include all roles for servers w/ >1 when they're requested" do
|
74
|
-
@capistrano.stubs(:whenever_roles).returns([:role1, :role2, :role3])
|
75
|
-
@capistrano.stubs(:role_names_for_host).with("foo").returns([:role1, :role3])
|
76
|
-
@capistrano.stubs(:role_names_for_host).with("bar").returns([:role2])
|
77
|
-
assert_equal({"foo" => [:role1, :role3], "bar" => [:role2]}, @capistrano.whenever_server_roles)
|
78
|
-
end
|
60
|
+
should "#whenever_run_commands: require :path arg" do
|
61
|
+
assert_raises ArgumentError do
|
62
|
+
@capistrano.whenever_run_commands(:options => {}, :command => {}, :flags => {})
|
79
63
|
end
|
64
|
+
end
|
65
|
+
|
66
|
+
should "#whenever_run_commands: require :flags arg" do
|
67
|
+
assert_raises ArgumentError do
|
68
|
+
@capistrano.whenever_run_commands(:options => {}, :path => {}, :command => {})
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
80
72
|
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
end
|
150
|
-
end
|
73
|
+
class ServerRolesTest < CapistranoTestCase
|
74
|
+
setup do
|
75
|
+
@mock_servers = ["foo", "bar"]
|
76
|
+
@capistrano.stubs(:whenever_servers).returns(@mock_servers)
|
77
|
+
|
78
|
+
@mock_server1, @mock_server2, @mock_server3 = mock("Server1"), mock("Server2"), mock("Server3")
|
79
|
+
@mock_server1.stubs(:host).returns("server1.foo.com")
|
80
|
+
@mock_server2.stubs(:host).returns("server2.foo.com")
|
81
|
+
@mock_server3.stubs(:host => "server3.foo.com", :port => 1022, :user => 'test')
|
82
|
+
@mock_servers = [@mock_server1, @mock_server2]
|
83
|
+
end
|
84
|
+
|
85
|
+
should "return a map of servers to their role(s)" do
|
86
|
+
@capistrano.stubs(:whenever_roles).returns([:role1, :role2])
|
87
|
+
@capistrano.stubs(:role_names_for_host).with("foo").returns([:role1])
|
88
|
+
@capistrano.stubs(:role_names_for_host).with("bar").returns([:role2])
|
89
|
+
assert_equal({"foo" => [:role1], "bar" => [:role2]}, @capistrano.whenever_server_roles)
|
90
|
+
end
|
91
|
+
|
92
|
+
should "exclude non-requested roles" do
|
93
|
+
@capistrano.stubs(:whenever_roles).returns([:role1, :role2])
|
94
|
+
@capistrano.stubs(:role_names_for_host).with("foo").returns([:role1, :role3])
|
95
|
+
@capistrano.stubs(:role_names_for_host).with("bar").returns([:role2])
|
96
|
+
assert_equal({"foo" => [:role1], "bar" => [:role2]}, @capistrano.whenever_server_roles)
|
97
|
+
end
|
98
|
+
|
99
|
+
should "include all roles for servers w/ >1 when they're requested" do
|
100
|
+
@capistrano.stubs(:whenever_roles).returns([:role1, :role2, :role3])
|
101
|
+
@capistrano.stubs(:role_names_for_host).with("foo").returns([:role1, :role3])
|
102
|
+
@capistrano.stubs(:role_names_for_host).with("bar").returns([:role2])
|
103
|
+
assert_equal({"foo" => [:role1, :role3], "bar" => [:role2]}, @capistrano.whenever_server_roles)
|
104
|
+
end
|
105
|
+
|
106
|
+
should "call run for each host w/ appropriate role args" do
|
107
|
+
@capistrano.stubs(:role_names_for_host).with(@mock_server1).returns([:role1])
|
108
|
+
@capistrano.stubs(:role_names_for_host).with(@mock_server2).returns([:role2])
|
109
|
+
@capistrano.stubs(:whenever_servers).returns(@mock_servers)
|
110
|
+
roles = [:role1, :role2]
|
111
|
+
@capistrano.stubs(:whenever_options).returns({:roles => roles})
|
112
|
+
|
113
|
+
@capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role1', {:roles => roles, :hosts => @mock_server1})
|
114
|
+
@capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role2', {:roles => roles, :hosts => @mock_server2})
|
115
|
+
|
116
|
+
@capistrano.whenever_run_commands(:command => "whenever",
|
117
|
+
:path => "/foo/bar",
|
118
|
+
:flags => "--flag1 --flag2")
|
119
|
+
end
|
120
|
+
|
121
|
+
should "call run w/ all role args for servers w/ >1 role" do
|
122
|
+
@capistrano.stubs(:role_names_for_host).with(@mock_server1).returns([:role1, :role3])
|
123
|
+
@capistrano.stubs(:whenever_servers).returns([@mock_server1])
|
124
|
+
roles = [:role1, :role2, :role3]
|
125
|
+
@capistrano.stubs(:whenever_options).returns({:roles => roles})
|
126
|
+
|
127
|
+
@capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role1,role3', {:roles => roles, :hosts => @mock_server1})
|
128
|
+
|
129
|
+
@capistrano.whenever_run_commands(:command => "whenever",
|
130
|
+
:path => "/foo/bar",
|
131
|
+
:flags => "--flag1 --flag2")
|
132
|
+
end
|
133
|
+
|
134
|
+
should "call run w/ proper server options (port, user)" do
|
135
|
+
@capistrano.stubs(:role_names_for_host).with(@mock_server3).returns([:role3])
|
136
|
+
@capistrano.stubs(:whenever_servers).returns([@mock_server3])
|
137
|
+
@capistrano.stubs(:whenever_options).returns({:roles => [:role3]})
|
138
|
+
|
139
|
+
@capistrano.expects(:run).once.with do |command, options|
|
140
|
+
options[:hosts].user == "test" && options[:hosts].port == 1022
|
151
141
|
end
|
142
|
+
|
143
|
+
@capistrano.whenever_run_commands(:command => "whenever",
|
144
|
+
:path => "/foo/bar",
|
145
|
+
:flags => "--flag1 --flag2")
|
152
146
|
end
|
153
147
|
end
|