minmb-capistrano 2.15.4

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.
Files changed (119) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +7 -0
  3. data/CHANGELOG +1170 -0
  4. data/Gemfile +13 -0
  5. data/README.md +94 -0
  6. data/Rakefile +11 -0
  7. data/bin/cap +4 -0
  8. data/bin/capify +92 -0
  9. data/capistrano.gemspec +40 -0
  10. data/lib/capistrano.rb +5 -0
  11. data/lib/capistrano/callback.rb +45 -0
  12. data/lib/capistrano/cli.rb +47 -0
  13. data/lib/capistrano/cli/execute.rb +85 -0
  14. data/lib/capistrano/cli/help.rb +125 -0
  15. data/lib/capistrano/cli/help.txt +81 -0
  16. data/lib/capistrano/cli/options.rb +243 -0
  17. data/lib/capistrano/cli/ui.rb +40 -0
  18. data/lib/capistrano/command.rb +303 -0
  19. data/lib/capistrano/configuration.rb +57 -0
  20. data/lib/capistrano/configuration/actions/file_transfer.rb +50 -0
  21. data/lib/capistrano/configuration/actions/inspect.rb +46 -0
  22. data/lib/capistrano/configuration/actions/invocation.rb +329 -0
  23. data/lib/capistrano/configuration/alias_task.rb +26 -0
  24. data/lib/capistrano/configuration/callbacks.rb +147 -0
  25. data/lib/capistrano/configuration/connections.rb +237 -0
  26. data/lib/capistrano/configuration/execution.rb +142 -0
  27. data/lib/capistrano/configuration/loading.rb +205 -0
  28. data/lib/capistrano/configuration/log_formatters.rb +75 -0
  29. data/lib/capistrano/configuration/namespaces.rb +223 -0
  30. data/lib/capistrano/configuration/roles.rb +77 -0
  31. data/lib/capistrano/configuration/servers.rb +116 -0
  32. data/lib/capistrano/configuration/variables.rb +127 -0
  33. data/lib/capistrano/errors.rb +19 -0
  34. data/lib/capistrano/ext/multistage.rb +64 -0
  35. data/lib/capistrano/ext/string.rb +5 -0
  36. data/lib/capistrano/extensions.rb +57 -0
  37. data/lib/capistrano/fix_rake_deprecated_dsl.rb +8 -0
  38. data/lib/capistrano/logger.rb +166 -0
  39. data/lib/capistrano/processable.rb +57 -0
  40. data/lib/capistrano/recipes/compat.rb +32 -0
  41. data/lib/capistrano/recipes/deploy.rb +625 -0
  42. data/lib/capistrano/recipes/deploy/assets.rb +201 -0
  43. data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
  44. data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
  45. data/lib/capistrano/recipes/deploy/remote_dependency.rb +117 -0
  46. data/lib/capistrano/recipes/deploy/scm.rb +19 -0
  47. data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
  48. data/lib/capistrano/recipes/deploy/scm/base.rb +200 -0
  49. data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
  50. data/lib/capistrano/recipes/deploy/scm/cvs.rb +153 -0
  51. data/lib/capistrano/recipes/deploy/scm/darcs.rb +96 -0
  52. data/lib/capistrano/recipes/deploy/scm/git.rb +293 -0
  53. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
  54. data/lib/capistrano/recipes/deploy/scm/none.rb +55 -0
  55. data/lib/capistrano/recipes/deploy/scm/perforce.rb +152 -0
  56. data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
  57. data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
  58. data/lib/capistrano/recipes/deploy/strategy/base.rb +92 -0
  59. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
  60. data/lib/capistrano/recipes/deploy/strategy/copy.rb +338 -0
  61. data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
  62. data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
  63. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +57 -0
  64. data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +21 -0
  65. data/lib/capistrano/recipes/standard.rb +37 -0
  66. data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
  67. data/lib/capistrano/role.rb +102 -0
  68. data/lib/capistrano/server_definition.rb +56 -0
  69. data/lib/capistrano/shell.rb +265 -0
  70. data/lib/capistrano/ssh.rb +95 -0
  71. data/lib/capistrano/task_definition.rb +77 -0
  72. data/lib/capistrano/transfer.rb +218 -0
  73. data/lib/capistrano/version.rb +11 -0
  74. data/test/cli/execute_test.rb +132 -0
  75. data/test/cli/help_test.rb +165 -0
  76. data/test/cli/options_test.rb +329 -0
  77. data/test/cli/ui_test.rb +28 -0
  78. data/test/cli_test.rb +17 -0
  79. data/test/command_test.rb +322 -0
  80. data/test/configuration/actions/file_transfer_test.rb +61 -0
  81. data/test/configuration/actions/inspect_test.rb +76 -0
  82. data/test/configuration/actions/invocation_test.rb +288 -0
  83. data/test/configuration/alias_task_test.rb +118 -0
  84. data/test/configuration/callbacks_test.rb +201 -0
  85. data/test/configuration/connections_test.rb +439 -0
  86. data/test/configuration/execution_test.rb +175 -0
  87. data/test/configuration/loading_test.rb +148 -0
  88. data/test/configuration/namespace_dsl_test.rb +332 -0
  89. data/test/configuration/roles_test.rb +157 -0
  90. data/test/configuration/servers_test.rb +183 -0
  91. data/test/configuration/variables_test.rb +190 -0
  92. data/test/configuration_test.rb +77 -0
  93. data/test/deploy/local_dependency_test.rb +76 -0
  94. data/test/deploy/remote_dependency_test.rb +146 -0
  95. data/test/deploy/scm/accurev_test.rb +23 -0
  96. data/test/deploy/scm/base_test.rb +55 -0
  97. data/test/deploy/scm/bzr_test.rb +51 -0
  98. data/test/deploy/scm/darcs_test.rb +37 -0
  99. data/test/deploy/scm/git_test.rb +221 -0
  100. data/test/deploy/scm/mercurial_test.rb +134 -0
  101. data/test/deploy/scm/none_test.rb +35 -0
  102. data/test/deploy/scm/perforce_test.rb +23 -0
  103. data/test/deploy/scm/subversion_test.rb +40 -0
  104. data/test/deploy/strategy/copy_test.rb +360 -0
  105. data/test/extensions_test.rb +69 -0
  106. data/test/fixtures/cli_integration.rb +5 -0
  107. data/test/fixtures/config.rb +5 -0
  108. data/test/fixtures/custom.rb +3 -0
  109. data/test/logger_formatting_test.rb +149 -0
  110. data/test/logger_test.rb +134 -0
  111. data/test/recipes_test.rb +25 -0
  112. data/test/role_test.rb +11 -0
  113. data/test/server_definition_test.rb +121 -0
  114. data/test/shell_test.rb +96 -0
  115. data/test/ssh_test.rb +113 -0
  116. data/test/task_definition_test.rb +117 -0
  117. data/test/transfer_test.rb +168 -0
  118. data/test/utils.rb +37 -0
  119. metadata +316 -0
@@ -0,0 +1,28 @@
1
+ require "utils"
2
+ require 'capistrano/cli/ui'
3
+
4
+ class CLIUITest < Test::Unit::TestCase
5
+ class MockCLI
6
+ include Capistrano::CLI::UI
7
+ end
8
+
9
+ def test_ui_should_return_highline_instance
10
+ assert_instance_of HighLine, MockCLI.ui
11
+ end
12
+
13
+ def test_password_prompt_should_have_default_prompt_and_set_echo_false
14
+ q = mock("question")
15
+ q.expects(:echo=).with(false)
16
+ ui = mock("ui")
17
+ ui.expects(:ask).with("Password: ").yields(q).returns("sayuncle")
18
+ MockCLI.expects(:ui).returns(ui)
19
+ assert_equal "sayuncle", MockCLI.password_prompt
20
+ end
21
+
22
+ def test_password_prompt_with_custom_prompt_should_use_custom_prompt
23
+ ui = mock("ui")
24
+ ui.expects(:ask).with("Give the passphrase: ").returns("sayuncle")
25
+ MockCLI.expects(:ui).returns(ui)
26
+ assert_equal "sayuncle", MockCLI.password_prompt("Give the passphrase: ")
27
+ end
28
+ end
data/test/cli_test.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "utils"
2
+ require 'capistrano/cli'
3
+
4
+ class CLI_Test < Test::Unit::TestCase
5
+ def test_options_ui_and_help_modules_should_integrate_successfully_with_configuration
6
+ cli = Capistrano::CLI.parse(%w(-T -x -X))
7
+ cli.expects(:puts).at_least_once
8
+ cli.execute!
9
+ end
10
+
11
+ def test_options_and_execute_modules_should_integrate_successfully_with_configuration
12
+ path = "#{File.dirname(__FILE__)}/fixtures/cli_integration.rb"
13
+ cli = Capistrano::CLI.parse(%W(-x -X -q -f #{path} testing))
14
+ config = cli.execute!
15
+ assert config[:testing_occurred]
16
+ end
17
+ end
@@ -0,0 +1,322 @@
1
+ require "utils"
2
+ require 'capistrano/command'
3
+ require 'capistrano/configuration'
4
+
5
+ class CommandTest < Test::Unit::TestCase
6
+ def test_command_should_open_channels_on_all_sessions
7
+ s1, s2, s3 = mock_session, mock_session, mock_session
8
+ assert_equal "ls", Capistrano::Command.new("ls", [s1, s2, s3]).tree.fallback.command
9
+ end
10
+
11
+ def test_command_with_newlines_should_be_properly_escaped
12
+ cmd = Capistrano::Command.new("ls\necho", [mock_session])
13
+ assert_equal "ls\\\necho", cmd.tree.fallback.command
14
+ end
15
+
16
+ def test_command_with_windows_newlines_should_be_properly_escaped
17
+ cmd = Capistrano::Command.new("ls\r\necho", [mock_session])
18
+ assert_equal "ls\\\necho", cmd.tree.fallback.command
19
+ end
20
+
21
+ def test_command_with_pty_should_request_pty_and_register_success_callback
22
+ session = setup_for_extracting_channel_action(:request_pty, true) do |ch|
23
+ ch.expects(:exec).with(%(sh -c 'ls'))
24
+ end
25
+ Capistrano::Command.new("ls", [session], :pty => true)
26
+ end
27
+
28
+ def test_command_with_env_key_should_have_environment_constructed_and_prepended
29
+ session = setup_for_extracting_channel_action do |ch|
30
+ ch.expects(:request_pty).never
31
+ ch.expects(:exec).with(%(env FOO=bar sh -c 'ls'))
32
+ end
33
+ Capistrano::Command.new("ls", [session], :env => { "FOO" => "bar" })
34
+ end
35
+
36
+ def test_env_with_symbolic_key_should_be_accepted_as_a_string
37
+ session = setup_for_extracting_channel_action do |ch|
38
+ ch.expects(:exec).with(%(env FOO=bar sh -c 'ls'))
39
+ end
40
+ Capistrano::Command.new("ls", [session], :env => { :FOO => "bar" })
41
+ end
42
+
43
+ def test_env_as_string_should_be_substituted_in_directly
44
+ session = setup_for_extracting_channel_action do |ch|
45
+ ch.expects(:exec).with(%(env HOWDY=there sh -c 'ls'))
46
+ end
47
+ Capistrano::Command.new("ls", [session], :env => "HOWDY=there")
48
+ end
49
+
50
+ def test_env_with_symbolic_value_should_be_accepted_as_string
51
+ session = setup_for_extracting_channel_action do |ch|
52
+ ch.expects(:exec).with(%(env FOO=bar sh -c 'ls'))
53
+ end
54
+ Capistrano::Command.new("ls", [session], :env => { "FOO" => :bar })
55
+ end
56
+
57
+ def test_env_value_should_be_escaped
58
+ session = setup_for_extracting_channel_action do |ch|
59
+ ch.expects(:exec).with(%(env FOO=(\\ \\\"bar\\\"\\ ) sh -c 'ls'))
60
+ end
61
+ Capistrano::Command.new("ls", [session], :env => { "FOO" => '( "bar" )' })
62
+ end
63
+
64
+ def test_env_with_multiple_keys_should_chain_the_entries_together
65
+ session = setup_for_extracting_channel_action do |ch|
66
+ ch.expects(:exec).with do |command|
67
+ command =~ /^env / &&
68
+ command =~ /\ba=b\b/ &&
69
+ command =~ /\bc=d\b/ &&
70
+ command =~ /\be=f\b/ &&
71
+ command =~ / sh -c 'ls'$/
72
+ end
73
+ end
74
+ Capistrano::Command.new("ls", [session], :env => { :a => :b, :c => :d, :e => :f })
75
+ end
76
+
77
+ def test_open_channel_should_set_host_key_on_channel
78
+ channel = nil
79
+ session = setup_for_extracting_channel_action { |ch| channel = ch }
80
+ Capistrano::Command.new("ls", [session])
81
+ assert_equal "capistrano", channel[:host]
82
+ end
83
+
84
+ def test_open_channel_should_set_options_key_on_channel
85
+ channel = nil
86
+ session = setup_for_extracting_channel_action { |ch| channel = ch }
87
+ Capistrano::Command.new("ls", [session], :data => "here we go")
88
+ assert_equal({ :data => 'here we go' }, channel[:options])
89
+ end
90
+
91
+ def test_successful_channel_should_send_command
92
+ session = setup_for_extracting_channel_action do |ch|
93
+ ch.expects(:exec).with(%(sh -c 'ls'))
94
+ end
95
+ Capistrano::Command.new("ls", [session])
96
+ end
97
+
98
+ def test_successful_channel_with_shell_option_should_send_command_via_specified_shell
99
+ session = setup_for_extracting_channel_action do |ch|
100
+ ch.expects(:exec).with(%(/bin/bash -c 'ls'))
101
+ end
102
+ Capistrano::Command.new("ls", [session], :shell => "/bin/bash")
103
+ end
104
+
105
+ def test_successful_channel_with_shell_false_should_send_command_without_shell
106
+ session = setup_for_extracting_channel_action do |ch|
107
+ ch.expects(:exec).with(%(echo `hostname`))
108
+ end
109
+ Capistrano::Command.new("echo `hostname`", [session], :shell => false)
110
+ end
111
+
112
+ def test_successful_channel_should_send_data_if_data_key_is_present
113
+ session = setup_for_extracting_channel_action do |ch|
114
+ ch.expects(:exec).with(%(sh -c 'ls'))
115
+ ch.expects(:send_data).with("here we go")
116
+ end
117
+ Capistrano::Command.new("ls", [session], :data => "here we go")
118
+ end
119
+
120
+ def test_unsuccessful_pty_request_should_close_channel
121
+ session = setup_for_extracting_channel_action(:request_pty, false) do |ch|
122
+ ch.expects(:close)
123
+ end
124
+ Capistrano::Command.new("ls", [session], :pty => true)
125
+ end
126
+
127
+ def test_on_data_should_invoke_callback_as_stdout
128
+ session = setup_for_extracting_channel_action(:on_data, "hello")
129
+ called = false
130
+ Capistrano::Command.new("ls", [session]) do |ch, stream, data|
131
+ called = true
132
+ assert_equal :out, stream
133
+ assert_equal "hello", data
134
+ end
135
+ assert called
136
+ end
137
+
138
+ def test_on_extended_data_should_invoke_callback_as_stderr
139
+ session = setup_for_extracting_channel_action(:on_extended_data, 2, "hello")
140
+ called = false
141
+ Capistrano::Command.new("ls", [session]) do |ch, stream, data|
142
+ called = true
143
+ assert_equal :err, stream
144
+ assert_equal "hello", data
145
+ end
146
+ assert called
147
+ end
148
+
149
+ def test_on_request_should_record_exit_status
150
+ data = mock(:read_long => 5)
151
+ channel = nil
152
+ session = setup_for_extracting_channel_action([:on_request, "exit-status"], data) { |ch| channel = ch }
153
+ Capistrano::Command.new("ls", [session])
154
+ assert_equal 5, channel[:status]
155
+ end
156
+
157
+ def test_on_request_should_log_exit_signal_if_logger_present
158
+ data = mock(:read_string => "TERM")
159
+ logger = stub_everything
160
+
161
+ session = setup_for_extracting_channel_action([:on_request, "exit-signal"], data)
162
+ logger.expects(:important).with("command received signal TERM", server("capistrano"))
163
+
164
+ Capistrano::Command.new("puppet", [session], :logger => logger)
165
+ end
166
+
167
+ def test_on_close_should_set_channel_closed
168
+ channel = nil
169
+ session = setup_for_extracting_channel_action(:on_close) { |ch| channel = ch }
170
+ Capistrano::Command.new("ls", [session])
171
+ assert channel[:closed]
172
+ end
173
+
174
+ def test_stop_should_close_all_open_channels
175
+ sessions = [mock_session(new_channel(false)),
176
+ mock_session(new_channel(true)),
177
+ mock_session(new_channel(false))]
178
+
179
+ cmd = Capistrano::Command.new("ls", sessions)
180
+ cmd.stop!
181
+ end
182
+
183
+ def test_process_should_return_cleanly_if_all_channels_have_zero_exit_status
184
+ sessions = [mock_session(new_channel(true, 0)),
185
+ mock_session(new_channel(true, 0)),
186
+ mock_session(new_channel(true, 0))]
187
+ cmd = Capistrano::Command.new("ls", sessions)
188
+ assert_nothing_raised { cmd.process! }
189
+ end
190
+
191
+ def test_process_should_raise_error_if_any_channel_has_non_zero_exit_status
192
+ sessions = [mock_session(new_channel(true, 0)),
193
+ mock_session(new_channel(true, 0)),
194
+ mock_session(new_channel(true, 1))]
195
+ cmd = Capistrano::Command.new("ls", sessions)
196
+ assert_raises(Capistrano::CommandError) { cmd.process! }
197
+ end
198
+
199
+ def test_command_error_should_include_accessor_with_host_array
200
+ sessions = [mock_session(new_channel(true, 0)),
201
+ mock_session(new_channel(true, 0)),
202
+ mock_session(new_channel(true, 1))]
203
+ cmd = Capistrano::Command.new("ls", sessions)
204
+
205
+ begin
206
+ cmd.process!
207
+ flunk "expected an exception to be raised"
208
+ rescue Capistrano::CommandError => e
209
+ assert e.respond_to?(:hosts)
210
+ assert_equal %w(capistrano), e.hosts.map { |h| h.to_s }
211
+ end
212
+ end
213
+
214
+ def test_process_should_loop_until_all_channels_are_closed
215
+ new_channel = Proc.new do |times|
216
+ ch = mock("channel")
217
+ returns = [false] * (times-1)
218
+ ch.stubs(:to_ary)
219
+ ch.stubs(:[]).with(:closed).returns(*(returns + [true]))
220
+ ch.expects(:[]).with(:status).returns(0)
221
+ ch
222
+ end
223
+
224
+ sessions = [mock_session(new_channel[5]),
225
+ mock_session(new_channel[10]),
226
+ mock_session(new_channel[7])]
227
+ cmd = Capistrano::Command.new("ls", sessions)
228
+ assert_nothing_raised do
229
+ cmd.process!
230
+ end
231
+ end
232
+
233
+ def test_process_should_instantiate_command_and_process!
234
+ cmd = mock("command", :process! => nil)
235
+ Capistrano::Command.expects(:new).with("ls -l", %w(a b c), {:foo => "bar"}).returns(cmd)
236
+ Capistrano::Command.process("ls -l", %w(a b c), :foo => "bar")
237
+ end
238
+
239
+ def test_process_with_host_placeholder_should_substitute_host_placeholder_with_each_host
240
+ session = setup_for_extracting_channel_action do |ch|
241
+ ch.expects(:exec).with(%(sh -c 'echo capistrano'))
242
+ end
243
+ Capistrano::Command.new("echo $CAPISTRANO:HOST$", [session])
244
+ end
245
+
246
+ class MockConfig
247
+ include Capistrano::Configuration::Roles
248
+ end
249
+
250
+ def test_hostroles_substitution
251
+ @config = MockConfig.new
252
+ @config.server "capistrano", :db, :worker
253
+ server = @config.roles[:db].servers.first
254
+ channel = {:server => server, :host => 'capistrano'}
255
+ tree = Capistrano::Command::Tree.new(@config) { |t| t.else("echo $CAPISTRANO:HOSTROLES$") }
256
+ result = Capistrano::Command.new(tree, []).send(:replace_placeholders, "echo $CAPISTRANO:HOSTROLES$", channel)
257
+ assert result == "echo db,worker" || result == "echo worker,db"
258
+ end
259
+
260
+ def test_process_with_unknown_placeholder_should_not_replace_placeholder
261
+ session = setup_for_extracting_channel_action do |ch|
262
+ ch.expects(:exec).with(%(sh -c 'echo $CAPISTRANO:OTHER$'))
263
+ end
264
+ Capistrano::Command.new("echo $CAPISTRANO:OTHER$", [session])
265
+ end
266
+
267
+ def test_input_stream_closed_when_eof_option_is_true
268
+ channel = nil
269
+ session = setup_for_extracting_channel_action { |ch| channel = ch }
270
+ channel.expects(:eof!)
271
+ Capistrano::Command.new("cat", [session], :data => "here we go", :eof => true)
272
+ assert_equal({ :data => 'here we go', :eof => true }, channel[:options])
273
+ end
274
+
275
+ private
276
+
277
+ def mock_session(channel=nil)
278
+ stub('session',
279
+ :open_channel => channel,
280
+ :preprocess => true,
281
+ :postprocess => true,
282
+ :listeners => {},
283
+ :xserver => server("capistrano"))
284
+ end
285
+
286
+ class MockChannel < Hash
287
+ def close
288
+ end
289
+ end
290
+
291
+ def new_channel(closed, status=nil)
292
+ ch = MockChannel.new
293
+ ch.update({ :closed => closed, :host => "capistrano", :server => server("capistrano") })
294
+ ch[:status] = status if status
295
+ ch.expects(:close) unless closed
296
+ ch
297
+ end
298
+
299
+ def setup_for_extracting_channel_action(action=nil, *args)
300
+ s = server("capistrano")
301
+ session = mock("session", :xserver => s)
302
+
303
+ channel = {}
304
+ session.expects(:open_channel).yields(channel)
305
+
306
+ channel.stubs(:on_data)
307
+ channel.stubs(:on_extended_data)
308
+ channel.stubs(:on_request)
309
+ channel.stubs(:on_close)
310
+ channel.stubs(:exec)
311
+ channel.stubs(:send_data)
312
+
313
+ if action
314
+ action = Array(action)
315
+ channel.expects(action.first).with(*action[1..-1]).yields(channel, *args)
316
+ end
317
+
318
+ yield channel if block_given?
319
+
320
+ session
321
+ end
322
+ end
@@ -0,0 +1,61 @@
1
+ require "utils"
2
+ require 'capistrano/configuration/actions/file_transfer'
3
+
4
+ class ConfigurationActionsFileTransferTest < Test::Unit::TestCase
5
+ class MockConfig
6
+ include Capistrano::Configuration::Actions::FileTransfer
7
+ attr_accessor :sessions, :dry_run
8
+ end
9
+
10
+ def setup
11
+ @config = MockConfig.new
12
+ @config.stubs(:logger).returns(stub_everything)
13
+ end
14
+
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 == { :mode => 0777 } }
18
+ @config.expects(:run).never
19
+ @config.put("some data", "test.txt", :mode => 0777)
20
+ end
21
+
22
+ def test_get_should_delegate_to_download_with_once
23
+ @config.expects(:download).with("testr.txt", "testl.txt", :foo => "bar", :once => true)
24
+ @config.get("testr.txt", "testl.txt", :foo => "bar")
25
+ end
26
+
27
+ def test_upload_should_delegate_to_transfer
28
+ @config.expects(:transfer).with(:up, "testl.txt", "testr.txt", :foo => "bar")
29
+ @config.upload("testl.txt", "testr.txt", :foo => "bar")
30
+ end
31
+
32
+ def test_upload_without_mode_should_not_try_to_chmod
33
+ @config.expects(:transfer).with(:up, "testl.txt", "testr.txt", :foo => "bar")
34
+ @config.expects(:run).never
35
+ @config.upload("testl.txt", "testr.txt", :foo => "bar")
36
+ end
37
+
38
+ def test_upload_with_mode_should_try_to_chmod
39
+ @config.expects(:transfer).with(:up, "testl.txt", "testr.txt", :foo => "bar")
40
+ @config.expects(:run).with("chmod 775 testr.txt", {:foo => "bar"})
41
+ @config.upload("testl.txt", "testr.txt", :mode => 0775, :foo => "bar")
42
+ end
43
+
44
+ def test_upload_with_symbolic_mode_should_try_to_chmod
45
+ @config.expects(:transfer).with(:up, "testl.txt", "testr.txt", :foo => "bar")
46
+ @config.expects(:run).with("chmod g+w testr.txt", {:foo => "bar"})
47
+ @config.upload("testl.txt", "testr.txt", :mode => "g+w", :foo => "bar")
48
+ end
49
+
50
+ def test_download_should_delegate_to_transfer
51
+ @config.expects(:transfer).with(:down, "testr.txt", "testl.txt", :foo => "bar")
52
+ @config.download("testr.txt", "testl.txt", :foo => "bar")
53
+ end
54
+
55
+ def test_transfer_should_invoke_transfer_on_matching_servers
56
+ @config.sessions = { :a => 1, :b => 2, :c => 3, :d => 4 }
57
+ @config.expects(:execute_on_servers).with(:foo => "bar").yields([:a, :b, :c])
58
+ Capistrano::Transfer.expects(:process).with(:up, "testl.txt", "testr.txt", [1,2,3], {:foo => "bar", :logger => @config.logger})
59
+ @config.transfer(:up, "testl.txt", "testr.txt", :foo => "bar")
60
+ end
61
+ end
@@ -0,0 +1,76 @@
1
+ require "utils"
2
+ require 'capistrano/configuration/actions/inspect'
3
+
4
+ class ConfigurationActionsInspectTest < Test::Unit::TestCase
5
+ class MockConfig
6
+ include Capistrano::Configuration::Actions::Inspect
7
+ end
8
+
9
+ def setup
10
+ @config = MockConfig.new
11
+ @config.stubs(:logger).returns(stub_everything)
12
+ @config.stubs(:sudo).returns('sudo')
13
+ end
14
+
15
+ def test_stream_should_pass_options_through_to_run
16
+ @config.expects(:invoke_command).with("tail -f foo.log", :once => true, :eof => true)
17
+ @config.stream("tail -f foo.log", :once => true)
18
+ end
19
+
20
+ def test_stream_with_sudo_should_avoid_closing_stdin
21
+ @config.expects(:invoke_command).with("sudo tail -f foo.log", :once => true, :eof => false)
22
+ @config.stream("sudo tail -f foo.log", :once => true)
23
+ end
24
+
25
+ def test_stream_should_emit_stdout_via_puts
26
+ @config.expects(:invoke_command).yields(mock("channel"), :out, "something streamed")
27
+ @config.expects(:puts).with("something streamed")
28
+ @config.expects(:warn).never
29
+ @config.stream("tail -f foo.log")
30
+ end
31
+
32
+ def test_stream_should_emit_stderr_via_warn
33
+ ch = mock("channel")
34
+ ch.expects(:[]).with(:server).returns(server("capistrano"))
35
+ @config.expects(:invoke_command).yields(ch, :err, "something streamed")
36
+ @config.expects(:puts).never
37
+ @config.expects(:warn).with("[err :: capistrano] something streamed")
38
+ @config.stream("tail -f foo.log")
39
+ end
40
+
41
+ def test_capture_should_pass_options_merged_with_once_to_run
42
+ @config.expects(:invoke_command).with("hostname", :foo => "bar", :once => true, :eof => true)
43
+ @config.capture("hostname", :foo => "bar")
44
+ end
45
+
46
+ def test_capture_with_sudo_should_avoid_closing_stdin
47
+ @config.expects(:invoke_command).with("sudo hostname", :foo => "bar", :once => true, :eof => false)
48
+ @config.capture("sudo hostname", :foo => "bar")
49
+ end
50
+
51
+ def test_capture_with_stderr_should_emit_stderr_via_warn
52
+ ch = mock("channel")
53
+ ch.expects(:[]).with(:server).returns(server("capistrano"))
54
+ @config.expects(:invoke_command).yields(ch, :err, "boom")
55
+ @config.expects(:warn).with("[err :: capistrano] boom")
56
+ @config.capture("hostname")
57
+ end
58
+
59
+ def test_capture_with_stdout_should_aggregate_and_return_stdout
60
+ config_expects_invoke_command_to_loop_with(mock("channel"), "foo", "bar", "baz")
61
+ assert_equal "foobarbaz", @config.capture("hostname")
62
+ end
63
+
64
+ private
65
+
66
+ def config_expects_invoke_command_to_loop_with(channel, *output)
67
+ class <<@config
68
+ attr_accessor :script, :channel
69
+ def invoke_command(*args)
70
+ script.each { |item| yield channel, :out, item }
71
+ end
72
+ end
73
+ @config.channel = channel
74
+ @config.script = output
75
+ end
76
+ end