capistrano 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +29 -0
- data/README +4 -7
- data/bin/cap +0 -0
- data/bin/capify +0 -0
- data/lib/capistrano/command.rb +32 -38
- data/lib/capistrano/configuration/actions/file_transfer.rb +21 -13
- data/lib/capistrano/configuration/actions/invocation.rb +1 -1
- data/lib/capistrano/configuration/connections.rb +30 -20
- data/lib/capistrano/errors.rb +1 -1
- data/lib/capistrano/processable.rb +53 -0
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +6 -0
- data/lib/capistrano/recipes/deploy/scm/git.rb +26 -11
- data/lib/capistrano/recipes/deploy/scm/none.rb +44 -0
- data/lib/capistrano/recipes/deploy/strategy/base.rb +6 -0
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +74 -3
- data/lib/capistrano/recipes/deploy.rb +15 -13
- data/lib/capistrano/role.rb +0 -14
- data/lib/capistrano/server_definition.rb +5 -0
- data/lib/capistrano/shell.rb +21 -17
- data/lib/capistrano/ssh.rb +24 -58
- data/lib/capistrano/transfer.rb +216 -0
- data/lib/capistrano/version.rb +1 -1
- data/test/cli/execute_test.rb +1 -1
- data/test/cli/help_test.rb +1 -1
- data/test/cli/options_test.rb +1 -1
- data/test/cli/ui_test.rb +1 -1
- data/test/cli_test.rb +1 -1
- data/test/command_test.rb +31 -51
- data/test/configuration/actions/file_transfer_test.rb +21 -19
- data/test/configuration/actions/inspect_test.rb +1 -1
- data/test/configuration/actions/invocation_test.rb +6 -6
- data/test/configuration/callbacks_test.rb +1 -1
- data/test/configuration/connections_test.rb +11 -12
- data/test/configuration/execution_test.rb +1 -1
- data/test/configuration/loading_test.rb +1 -1
- data/test/configuration/namespace_dsl_test.rb +1 -1
- data/test/configuration/roles_test.rb +1 -1
- data/test/configuration/servers_test.rb +1 -1
- data/test/configuration/variables_test.rb +1 -1
- data/test/configuration_test.rb +1 -1
- data/test/deploy/scm/accurev_test.rb +1 -1
- data/test/deploy/scm/base_test.rb +1 -1
- data/test/deploy/scm/git_test.rb +10 -6
- data/test/deploy/scm/mercurial_test.rb +1 -1
- data/test/deploy/strategy/copy_test.rb +120 -27
- data/test/extensions_test.rb +1 -1
- data/test/logger_test.rb +1 -1
- data/test/server_definition_test.rb +1 -1
- data/test/shell_test.rb +27 -1
- data/test/ssh_test.rb +27 -21
- data/test/task_definition_test.rb +1 -1
- data/test/transfer_test.rb +160 -0
- data/test/utils.rb +30 -34
- data/test/version_test.rb +1 -1
- metadata +26 -14
- data/lib/capistrano/gateway.rb +0 -131
- data/lib/capistrano/upload.rb +0 -152
- data/test/gateway_test.rb +0 -167
- data/test/upload_test.rb +0 -131
data/test/command_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "utils"
|
2
2
|
require 'capistrano/command'
|
3
3
|
|
4
4
|
class CommandTest < Test::Unit::TestCase
|
@@ -20,8 +20,7 @@ class CommandTest < Test::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_command_with_pty_should_request_pty_and_register_success_callback
|
23
|
-
session = setup_for_extracting_channel_action(:
|
24
|
-
ch.expects(:request_pty).with(:want_reply => true)
|
23
|
+
session = setup_for_extracting_channel_action(:request_pty, true) do |ch|
|
25
24
|
ch.expects(:exec).with(%(sh -c "ls"))
|
26
25
|
end
|
27
26
|
Capistrano::Command.new("ls", [session], :pty => true)
|
@@ -128,7 +127,7 @@ class CommandTest < Test::Unit::TestCase
|
|
128
127
|
end
|
129
128
|
|
130
129
|
def test_unsuccessful_pty_request_should_close_channel
|
131
|
-
session = setup_for_extracting_channel_action(:
|
130
|
+
session = setup_for_extracting_channel_action(:request_pty, false) do |ch|
|
132
131
|
ch.expects(:close)
|
133
132
|
end
|
134
133
|
Capistrano::Command.new("ls", [session], :pty => true)
|
@@ -158,7 +157,7 @@ class CommandTest < Test::Unit::TestCase
|
|
158
157
|
|
159
158
|
def test_on_request_should_record_exit_status
|
160
159
|
data = mock(:read_long => 5)
|
161
|
-
session = setup_for_extracting_channel_action(:on_request, "exit-status",
|
160
|
+
session = setup_for_extracting_channel_action([:on_request, "exit-status"], data) do |ch|
|
162
161
|
ch.expects(:[]=).with(:status, 5)
|
163
162
|
end
|
164
163
|
Capistrano::Command.new("ls", [session])
|
@@ -172,34 +171,34 @@ class CommandTest < Test::Unit::TestCase
|
|
172
171
|
end
|
173
172
|
|
174
173
|
def test_stop_should_close_all_open_channels
|
175
|
-
sessions = [
|
176
|
-
|
177
|
-
|
174
|
+
sessions = [mock_session(new_channel(false)),
|
175
|
+
mock_session(new_channel(true)),
|
176
|
+
mock_session(new_channel(false))]
|
178
177
|
|
179
178
|
cmd = Capistrano::Command.new("ls", sessions)
|
180
179
|
cmd.stop!
|
181
180
|
end
|
182
181
|
|
183
182
|
def test_process_should_return_cleanly_if_all_channels_have_zero_exit_status
|
184
|
-
sessions = [
|
185
|
-
|
186
|
-
|
183
|
+
sessions = [mock_session(new_channel(true, 0)),
|
184
|
+
mock_session(new_channel(true, 0)),
|
185
|
+
mock_session(new_channel(true, 0))]
|
187
186
|
cmd = Capistrano::Command.new("ls", sessions)
|
188
187
|
assert_nothing_raised { cmd.process! }
|
189
188
|
end
|
190
189
|
|
191
190
|
def test_process_should_raise_error_if_any_channel_has_non_zero_exit_status
|
192
|
-
sessions = [
|
193
|
-
|
194
|
-
|
191
|
+
sessions = [mock_session(new_channel(true, 0)),
|
192
|
+
mock_session(new_channel(true, 0)),
|
193
|
+
mock_session(new_channel(true, 1))]
|
195
194
|
cmd = Capistrano::Command.new("ls", sessions)
|
196
195
|
assert_raises(Capistrano::CommandError) { cmd.process! }
|
197
196
|
end
|
198
197
|
|
199
198
|
def test_command_error_should_include_accessor_with_host_array
|
200
|
-
sessions = [
|
201
|
-
|
202
|
-
|
199
|
+
sessions = [mock_session(new_channel(true, 0)),
|
200
|
+
mock_session(new_channel(true, 0)),
|
201
|
+
mock_session(new_channel(true, 1))]
|
203
202
|
cmd = Capistrano::Command.new("ls", sessions)
|
204
203
|
|
205
204
|
begin
|
@@ -216,43 +215,13 @@ class CommandTest < Test::Unit::TestCase
|
|
216
215
|
ch = mock("channel")
|
217
216
|
returns = [false] * (times-1)
|
218
217
|
ch.stubs(:[]).with(:closed).returns(*(returns + [true]))
|
219
|
-
con = mock("connection")
|
220
|
-
con.expects(:process).with(true).times(times-1)
|
221
|
-
ch.expects(:connection).times(times-1).returns(con)
|
222
218
|
ch.expects(:[]).with(:status).returns(0)
|
223
219
|
ch
|
224
220
|
end
|
225
221
|
|
226
|
-
sessions = [
|
227
|
-
|
228
|
-
|
229
|
-
cmd = Capistrano::Command.new("ls", sessions)
|
230
|
-
assert_nothing_raised { cmd.process! }
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_process_should_ping_all_connections_each_second
|
234
|
-
now = Time.now
|
235
|
-
|
236
|
-
new_channel = Proc.new do
|
237
|
-
ch = mock("channel")
|
238
|
-
ch.stubs(:now => now)
|
239
|
-
def ch.[](key)
|
240
|
-
case key
|
241
|
-
when :status then 0
|
242
|
-
when :closed then Time.now - now < 1.1 ? false : true
|
243
|
-
else raise "unknown key: #{key}"
|
244
|
-
end
|
245
|
-
end
|
246
|
-
con = mock("connection")
|
247
|
-
con.stubs(:process)
|
248
|
-
con.expects(:ping!)
|
249
|
-
ch.stubs(:connection).returns(con)
|
250
|
-
ch
|
251
|
-
end
|
252
|
-
|
253
|
-
sessions = [mock("session", :open_channel => new_channel[]),
|
254
|
-
mock("session", :open_channel => new_channel[]),
|
255
|
-
mock("session", :open_channel => new_channel[])]
|
222
|
+
sessions = [mock_session(new_channel[5]),
|
223
|
+
mock_session(new_channel[10]),
|
224
|
+
mock_session(new_channel[7])]
|
256
225
|
cmd = Capistrano::Command.new("ls", sessions)
|
257
226
|
assert_nothing_raised { cmd.process! }
|
258
227
|
end
|
@@ -281,6 +250,13 @@ class CommandTest < Test::Unit::TestCase
|
|
281
250
|
|
282
251
|
private
|
283
252
|
|
253
|
+
def mock_session(channel=nil)
|
254
|
+
stub('session', :open_channel => channel,
|
255
|
+
:preprocess => true,
|
256
|
+
:postprocess => true,
|
257
|
+
:listeners => {})
|
258
|
+
end
|
259
|
+
|
284
260
|
def new_channel(closed, status=nil)
|
285
261
|
ch = mock("channel")
|
286
262
|
ch.expects(:[]).with(:closed).returns(closed)
|
@@ -300,7 +276,11 @@ class CommandTest < Test::Unit::TestCase
|
|
300
276
|
|
301
277
|
channel.stubs(:[]).with(:server).returns(s)
|
302
278
|
channel.stubs(:[]).with(:host).returns(s.host)
|
303
|
-
|
279
|
+
|
280
|
+
if action
|
281
|
+
action = Array(action)
|
282
|
+
channel.expects(action.first).with(*action[1..-1]).yields(channel, *args)
|
283
|
+
end
|
304
284
|
|
305
285
|
yield channel if block_given?
|
306
286
|
|
@@ -1,9 +1,10 @@
|
|
1
|
-
require "
|
1
|
+
require "utils"
|
2
2
|
require 'capistrano/configuration/actions/file_transfer'
|
3
3
|
|
4
4
|
class ConfigurationActionsFileTransferTest < Test::Unit::TestCase
|
5
5
|
class MockConfig
|
6
6
|
include Capistrano::Configuration::Actions::FileTransfer
|
7
|
+
attr_accessor :sessions
|
7
8
|
end
|
8
9
|
|
9
10
|
def setup
|
@@ -11,30 +12,31 @@ class ConfigurationActionsFileTransferTest < Test::Unit::TestCase
|
|
11
12
|
@config.stubs(:logger).returns(stub_everything)
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
@config.expects(:
|
16
|
-
|
15
|
+
def test_put_should_delegate_to_upload
|
16
|
+
@config.expects(:upload).with { |from, to, opts|
|
17
|
+
from.string == "some data" && to == "test.txt" && opts == { :permissions => 0777 } }
|
18
|
+
@config.put("some data", "test.txt", :mode => 0777)
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
20
|
-
@config.expects(:
|
21
|
-
@config.
|
22
|
-
Capistrano::Upload.expects(:process).with([:s1,:s2,:s3], "test.txt", :data => "some data", :mode => 0777, :logger => @config.logger)
|
23
|
-
@config.put("some data", "test.txt", :mode => 0777)
|
21
|
+
def test_get_should_delegate_to_download_with_once
|
22
|
+
@config.expects(:download).with("testr.txt", "testl.txt", :foo => "bar", :once => true)
|
23
|
+
@config.get("testr.txt", "testl.txt", :foo => "bar")
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
@config.expects(:
|
28
|
-
@config.
|
26
|
+
def test_upload_should_delegate_to_transfer
|
27
|
+
@config.expects(:transfer).with(:up, "testl.txt", "testr.txt", :foo => "bar")
|
28
|
+
@config.upload("testl.txt", "testr.txt", :foo => "bar")
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
31
|
+
def test_download_should_delegate_to_transfer
|
32
|
+
@config.expects(:transfer).with(:down, "testr.txt", "testl.txt", :foo => "bar")
|
33
|
+
@config.download("testr.txt", "testl.txt", :foo => "bar")
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
@config.
|
37
|
-
@config.expects(:
|
38
|
-
|
36
|
+
def test_transfer_should_invoke_transfer_on_matching_servers
|
37
|
+
@config.sessions = { :a => 1, :b => 2, :c => 3, :d => 4 }
|
38
|
+
@config.expects(:execute_on_servers).with(:foo => "bar").yields([:a, :b, :c])
|
39
|
+
Capistrano::Transfer.expects(:process).with(:up, "testl.txt", "testr.txt", [1,2,3], {:foo => "bar", :logger => @config.logger})
|
40
|
+
@config.transfer(:up, "testl.txt", "testr.txt", :foo => "bar")
|
39
41
|
end
|
40
42
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "utils"
|
2
2
|
require 'capistrano/configuration/actions/invocation'
|
3
3
|
|
4
4
|
class ConfigurationActionsInvocationTest < Test::Unit::TestCase
|
@@ -97,29 +97,29 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def test_sudo_should_default_to_sudo
|
100
|
-
@config.expects(:run).with("sudo -p 'sudo password: '
|
100
|
+
@config.expects(:run).with("ls", :command_prefix => "sudo -p 'sudo password: '")
|
101
101
|
@config.sudo "ls"
|
102
102
|
end
|
103
103
|
|
104
104
|
def test_sudo_should_use_sudo_variable_definition
|
105
|
-
@config.expects(:run).with("/opt/local/bin/sudo -p 'sudo password: '
|
105
|
+
@config.expects(:run).with("ls", :command_prefix => "/opt/local/bin/sudo -p 'sudo password: '")
|
106
106
|
@config.options[:sudo] = "/opt/local/bin/sudo"
|
107
107
|
@config.sudo "ls"
|
108
108
|
end
|
109
109
|
|
110
110
|
def test_sudo_should_interpret_as_option_as_user
|
111
|
-
@config.expects(:run).with("sudo -p 'sudo password: ' -u app
|
111
|
+
@config.expects(:run).with("ls", :command_prefix => "sudo -p 'sudo password: ' -u app")
|
112
112
|
@config.sudo "ls", :as => "app"
|
113
113
|
end
|
114
114
|
|
115
115
|
def test_sudo_should_pass_options_through_to_run
|
116
|
-
@config.expects(:run).with("sudo -p 'sudo password: '
|
116
|
+
@config.expects(:run).with("ls", :command_prefix => "sudo -p 'sudo password: '", :foo => "bar")
|
117
117
|
@config.sudo "ls", :foo => "bar"
|
118
118
|
end
|
119
119
|
|
120
120
|
def test_sudo_should_interpret_sudo_prompt_variable_as_custom_prompt
|
121
121
|
@config.set :sudo_prompt, "give it to me: "
|
122
|
-
@config.expects(:run).with("sudo -p 'give it to me: '
|
122
|
+
@config.expects(:run).with("ls", :command_prefix => "sudo -p 'give it to me: '")
|
123
123
|
@config.sudo "ls"
|
124
124
|
end
|
125
125
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "utils"
|
2
2
|
require 'capistrano/configuration/connections'
|
3
3
|
|
4
4
|
class ConfigurationConnectionsTest < Test::Unit::TestCase
|
@@ -31,7 +31,7 @@ class ConfigurationConnectionsTest < Test::Unit::TestCase
|
|
31
31
|
@config = MockConfig.new
|
32
32
|
@config.stubs(:logger).returns(stub_everything)
|
33
33
|
@ssh_options = {
|
34
|
-
:user => "
|
34
|
+
:user => "user",
|
35
35
|
:port => 8080,
|
36
36
|
:password => "g00b3r",
|
37
37
|
:ssh_options => { :debug => :verbose }
|
@@ -59,17 +59,16 @@ class ConfigurationConnectionsTest < Test::Unit::TestCase
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_connection_factory_should_return_gateway_instance_if_gateway_variable_is_set
|
62
|
-
@config.values[:gateway] = "capistrano"
|
63
|
-
|
64
|
-
Capistrano::
|
65
|
-
assert_instance_of Capistrano::Gateway, @config.connection_factory
|
62
|
+
@config.values[:gateway] = "j@capistrano"
|
63
|
+
Net::SSH::Gateway.expects(:new).with("capistrano", "j", :port => 22, :password => nil, :auth_methods => %w(publickey hostbased)).returns(stub_everything)
|
64
|
+
assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
|
66
65
|
end
|
67
66
|
|
68
67
|
def test_connection_factory_as_gateway_should_honor_config_options
|
69
68
|
@config.values[:gateway] = "capistrano"
|
70
69
|
@config.values.update(@ssh_options)
|
71
|
-
|
72
|
-
assert_instance_of Capistrano::
|
70
|
+
Net::SSH::Gateway.expects(:new).with("capistrano", "user", :debug => :verbose, :port => 8080, :password => nil, :auth_methods => %w(publickey hostbased)).returns(stub_everything)
|
71
|
+
assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
|
73
72
|
end
|
74
73
|
|
75
74
|
def test_establish_connections_to_should_accept_a_single_nonarray_parameter
|
@@ -194,11 +193,11 @@ class ConfigurationConnectionsTest < Test::Unit::TestCase
|
|
194
193
|
@config.current_task = mock_task
|
195
194
|
@config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([server("cap1")])
|
196
195
|
Capistrano::SSH.expects(:connect).raises(Exception)
|
197
|
-
assert_raises(Capistrano::ConnectionError)
|
196
|
+
assert_raises(Capistrano::ConnectionError) do
|
198
197
|
@config.execute_on_servers do
|
199
198
|
flunk "expected an exception to be raised"
|
200
199
|
end
|
201
|
-
|
200
|
+
end
|
202
201
|
end
|
203
202
|
|
204
203
|
def test_execute_servers_should_not_raise_connection_error_on_failure_with_on_errors_continue
|
@@ -243,14 +242,14 @@ class ConfigurationConnectionsTest < Test::Unit::TestCase
|
|
243
242
|
end
|
244
243
|
end
|
245
244
|
|
246
|
-
def
|
245
|
+
def test_execute_on_servers_should_not_try_to_connect_to_hosts_with_transfer_errors_with_on_errors_continue
|
247
246
|
cap1 = server("cap1")
|
248
247
|
cap2 = server("cap2")
|
249
248
|
@config.current_task = mock_task(:on_error => :continue)
|
250
249
|
@config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([cap1, cap2])
|
251
250
|
Capistrano::SSH.expects(:connect).times(2).returns(:success)
|
252
251
|
@config.execute_on_servers do |servers|
|
253
|
-
error = Capistrano::
|
252
|
+
error = Capistrano::TransferError.new
|
254
253
|
error.hosts = [cap1]
|
255
254
|
raise error
|
256
255
|
end
|
data/test/configuration_test.rb
CHANGED
data/test/deploy/scm/git_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "utils"
|
2
2
|
require 'capistrano/recipes/deploy/scm/git'
|
3
3
|
|
4
4
|
class DeploySCMGitTest < Test::Unit::TestCase
|
@@ -7,7 +7,7 @@ class DeploySCMGitTest < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def setup
|
10
|
-
@config = { }
|
10
|
+
@config = { :repository => "." }
|
11
11
|
def @config.exists?(name); key?(name); end
|
12
12
|
|
13
13
|
@source = TestSCM.new(@config)
|
@@ -50,7 +50,11 @@ class DeploySCMGitTest < Test::Unit::TestCase
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_query_revision
|
53
|
-
|
53
|
+
revision = @source.query_revision('HEAD') do |o|
|
54
|
+
assert_equal "git ls-remote . HEAD", o
|
55
|
+
"d11006102c07c94e5d54dd0ee63dca825c93ed61\tHEAD"
|
56
|
+
end
|
57
|
+
assert_equal "d11006102c07c94e5d54dd0ee63dca825c93ed61", revision
|
54
58
|
end
|
55
59
|
|
56
60
|
def test_command_should_be_backwards_compatible
|
@@ -62,12 +66,12 @@ class DeploySCMGitTest < Test::Unit::TestCase
|
|
62
66
|
def test_sync
|
63
67
|
dest = "/var/www"
|
64
68
|
rev = 'c2d9e79'
|
65
|
-
assert_equal "cd #{dest} && git fetch origin && git reset --hard #{rev}", @source.sync(rev, dest)
|
69
|
+
assert_equal "cd #{dest} && git fetch --tags origin && git reset --hard #{rev}", @source.sync(rev, dest)
|
66
70
|
|
67
71
|
# With :scm_command
|
68
72
|
git = "/opt/local/bin/git"
|
69
73
|
@config[:scm_command] = git
|
70
|
-
assert_equal "cd #{dest} && #{git} fetch origin && #{git} reset --hard #{rev}", @source.sync(rev, dest)
|
74
|
+
assert_equal "cd #{dest} && #{git} fetch --tags origin && #{git} reset --hard #{rev}", @source.sync(rev, dest)
|
71
75
|
end
|
72
76
|
|
73
77
|
def test_sync_with_remote
|
@@ -79,7 +83,7 @@ class DeploySCMGitTest < Test::Unit::TestCase
|
|
79
83
|
@config[:repository] = repository
|
80
84
|
@config[:remote] = remote
|
81
85
|
|
82
|
-
assert_equal "cd #{dest} && git config remote.#{remote}.url #{repository} && git config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/* && git fetch #{remote} && git reset --hard #{rev}", @source.sync(rev, dest)
|
86
|
+
assert_equal "cd #{dest} && git config remote.#{remote}.url #{repository} && git config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/* && git fetch --tags #{remote} && git reset --hard #{rev}", @source.sync(rev, dest)
|
83
87
|
end
|
84
88
|
|
85
89
|
def test_shallow_clone
|
@@ -1,11 +1,12 @@
|
|
1
|
-
require "
|
1
|
+
require "utils"
|
2
2
|
require 'capistrano/logger'
|
3
3
|
require 'capistrano/recipes/deploy/strategy/copy'
|
4
4
|
require 'stringio'
|
5
5
|
|
6
6
|
class DeployStrategyCopyTest < Test::Unit::TestCase
|
7
7
|
def setup
|
8
|
-
@config = { :
|
8
|
+
@config = { :application => "captest",
|
9
|
+
:logger => Capistrano::Logger.new(:output => StringIO.new),
|
9
10
|
:releases_path => "/u/apps/test/releases",
|
10
11
|
:release_path => "/u/apps/test/releases/1234567890",
|
11
12
|
:real_revision => "154" }
|
@@ -16,44 +17,31 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
16
17
|
|
17
18
|
def test_deploy_with_defaults_should_use_tar_gz_and_checkout
|
18
19
|
Dir.expects(:tmpdir).returns("/temp/dir")
|
19
|
-
Dir.expects(:chdir).with("/temp/dir").yields
|
20
20
|
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
21
|
-
|
22
21
|
@strategy.expects(:system).with(:local_checkout)
|
23
|
-
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
24
|
-
@strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.gz")
|
25
|
-
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
File.expects(:open).with("/temp/dir/1234567890.tar.gz", "rb").yields(StringIO.new).returns(:mock_file_contents)
|
23
|
+
prepare_standard_compress_and_copy!
|
24
|
+
@strategy.deploy!
|
25
|
+
end
|
31
26
|
|
32
|
-
|
33
|
-
|
27
|
+
def test_deploy_with_exclusions_should_remove_patterns_from_destination
|
28
|
+
@config[:copy_exclude] = ".git"
|
29
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
30
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
31
|
+
@strategy.expects(:system).with(:local_checkout)
|
34
32
|
|
33
|
+
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890/.git")
|
34
|
+
prepare_standard_compress_and_copy!
|
35
35
|
@strategy.deploy!
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_deploy_with_export_should_use_tar_gz_and_export
|
39
39
|
Dir.expects(:tmpdir).returns("/temp/dir")
|
40
|
-
Dir.expects(:chdir).with("/temp/dir").yields
|
41
40
|
@config[:copy_strategy] = :export
|
42
41
|
@source.expects(:export).with("154", "/temp/dir/1234567890").returns(:local_export)
|
43
|
-
|
44
42
|
@strategy.expects(:system).with(:local_export)
|
45
|
-
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
46
|
-
@strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.gz")
|
47
|
-
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
48
|
-
|
49
|
-
mock_file = mock("file")
|
50
|
-
mock_file.expects(:puts).with("154")
|
51
|
-
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
52
|
-
File.expects(:open).with("/temp/dir/1234567890.tar.gz", "rb").yields(StringIO.new).returns(:mock_file_contents)
|
53
|
-
|
54
|
-
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
55
|
-
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
56
43
|
|
44
|
+
prepare_standard_compress_and_copy!
|
57
45
|
@strategy.deploy!
|
58
46
|
end
|
59
47
|
|
@@ -79,7 +67,7 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
79
67
|
@strategy.deploy!
|
80
68
|
end
|
81
69
|
|
82
|
-
def
|
70
|
+
def test_deploy_with_bzip2_should_use_bz2_and_checkout
|
83
71
|
Dir.expects(:tmpdir).returns("/temp/dir")
|
84
72
|
Dir.expects(:chdir).with("/temp/dir").yields
|
85
73
|
@config[:copy_compression] = :bzip2
|
@@ -144,4 +132,109 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
144
132
|
|
145
133
|
@strategy.deploy!
|
146
134
|
end
|
135
|
+
|
136
|
+
def test_with_copy_cache_should_checkout_to_cache_if_cache_does_not_exist_and_then_copy
|
137
|
+
@config[:copy_cache] = true
|
138
|
+
|
139
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
140
|
+
File.expects(:exists?).with("/temp/dir/captest").returns(false)
|
141
|
+
Dir.expects(:chdir).with("/temp/dir/captest").yields
|
142
|
+
|
143
|
+
@source.expects(:checkout).with("154", "/temp/dir/captest").returns(:local_checkout)
|
144
|
+
@strategy.expects(:system).with(:local_checkout)
|
145
|
+
|
146
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
147
|
+
|
148
|
+
prepare_directory_tree!("/temp/dir/captest")
|
149
|
+
|
150
|
+
prepare_standard_compress_and_copy!
|
151
|
+
@strategy.deploy!
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_with_copy_cache_should_update_cache_if_cache_exists_and_then_copy
|
155
|
+
@config[:copy_cache] = true
|
156
|
+
|
157
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
158
|
+
File.expects(:exists?).with("/temp/dir/captest").returns(true)
|
159
|
+
Dir.expects(:chdir).with("/temp/dir/captest").yields
|
160
|
+
|
161
|
+
@source.expects(:sync).with("154", "/temp/dir/captest").returns(:local_sync)
|
162
|
+
@strategy.expects(:system).with(:local_sync)
|
163
|
+
|
164
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
165
|
+
|
166
|
+
prepare_directory_tree!("/temp/dir/captest")
|
167
|
+
|
168
|
+
prepare_standard_compress_and_copy!
|
169
|
+
@strategy.deploy!
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_with_copy_cache_with_custom_cache_dir_should_use_specified_cache_dir
|
173
|
+
@config[:copy_cache] = "/u/caches/captest"
|
174
|
+
|
175
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
176
|
+
File.expects(:exists?).with("/u/caches/captest").returns(true)
|
177
|
+
Dir.expects(:chdir).with("/u/caches/captest").yields
|
178
|
+
|
179
|
+
@source.expects(:sync).with("154", "/u/caches/captest").returns(:local_sync)
|
180
|
+
@strategy.expects(:system).with(:local_sync)
|
181
|
+
|
182
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
183
|
+
|
184
|
+
prepare_directory_tree!("/u/caches/captest")
|
185
|
+
|
186
|
+
prepare_standard_compress_and_copy!
|
187
|
+
@strategy.deploy!
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_with_copy_cache_with_excludes_should_not_copy_excluded_files
|
191
|
+
@config[:copy_cache] = true
|
192
|
+
@config[:copy_exclude] = "*/bar.txt"
|
193
|
+
|
194
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
195
|
+
File.expects(:exists?).with("/temp/dir/captest").returns(true)
|
196
|
+
Dir.expects(:chdir).with("/temp/dir/captest").yields
|
197
|
+
|
198
|
+
@source.expects(:sync).with("154", "/temp/dir/captest").returns(:local_sync)
|
199
|
+
@strategy.expects(:system).with(:local_sync)
|
200
|
+
|
201
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
202
|
+
|
203
|
+
prepare_directory_tree!("/temp/dir/captest", true)
|
204
|
+
|
205
|
+
prepare_standard_compress_and_copy!
|
206
|
+
@strategy.deploy!
|
207
|
+
end
|
208
|
+
|
209
|
+
private
|
210
|
+
|
211
|
+
def prepare_directory_tree!(cache, exclude=false)
|
212
|
+
Dir.expects(:glob).with("*", File::FNM_DOTMATCH).returns([".", "..", "app", "foo.txt"])
|
213
|
+
File.expects(:directory?).with("app").returns(true)
|
214
|
+
FileUtils.expects(:mkdir).with("/temp/dir/1234567890/app")
|
215
|
+
File.expects(:directory?).with("foo.txt").returns(false)
|
216
|
+
FileUtils.expects(:ln).with("#{cache}/foo.txt", "/temp/dir/1234567890/foo.txt")
|
217
|
+
|
218
|
+
Dir.expects(:glob).with("app/*", File::FNM_DOTMATCH).returns(["app/.", "app/..", "app/bar.txt"])
|
219
|
+
|
220
|
+
unless exclude
|
221
|
+
File.expects(:directory?).with("app/bar.txt").returns(false)
|
222
|
+
FileUtils.expects(:ln).with("#{cache}/app/bar.txt", "/temp/dir/1234567890/app/bar.txt")
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def prepare_standard_compress_and_copy!
|
227
|
+
Dir.expects(:chdir).with("/temp/dir").yields
|
228
|
+
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
229
|
+
@strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.gz")
|
230
|
+
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
231
|
+
|
232
|
+
mock_file = mock("file")
|
233
|
+
mock_file.expects(:puts).with("154")
|
234
|
+
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
235
|
+
File.expects(:open).with("/temp/dir/1234567890.tar.gz", "rb").yields(StringIO.new).returns(:mock_file_contents)
|
236
|
+
|
237
|
+
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
238
|
+
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
239
|
+
end
|
147
240
|
end
|