Changeset 7387
- Timestamp:
- 09/01/07 03:23:51 (11 months ago)
- Files:
-
- tools/capistrano/CHANGELOG (modified) (1 diff)
- tools/capistrano/lib/capistrano/command.rb (modified) (2 diffs)
- tools/capistrano/lib/capistrano/configuration/actions/invocation.rb (modified) (2 diffs)
- tools/capistrano/test/command_test.rb (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tools/capistrano/CHANGELOG
r7386 r7387 1 1 *SVN* 2 3 * Don't request a pty by default [Jamis Buck] 2 4 3 5 * Add a "match" remote dependency method [Adam Greene] tools/capistrano/lib/capistrano/command.rb
r7112 r7387 84 84 channel[:host] = server.host 85 85 channel[:options] = options 86 channel.request_pty :want_reply => true87 86 88 channel.on_successdo |ch|87 execute_command = Proc.new do |ch| 89 88 logger.trace "executing command", ch[:server] if logger 90 89 escaped = replace_placeholders(command, ch).gsub(/[$\\`"]/) { |m| "\\#{m}" } … … 94 93 end 95 94 96 channel.on_failure do |ch| 97 # just log it, don't actually raise an exception, since the 98 # process method will see that the status is not zero and will 99 # raise an exception then. 100 logger.important "could not open channel", ch[:server] if logger 101 ch.close 95 if options[:pty] 96 channel.request_pty(:want_reply => true) 97 channel.on_success(&execute_command) 98 channel.on_failure do |ch| 99 # just log it, don't actually raise an exception, since the 100 # process method will see that the status is not zero and will 101 # raise an exception then. 102 logger.important "could not open channel", ch[:server] if logger 103 ch.close 104 end 105 else 106 execute_command.call(channel) 102 107 end 103 108 104 109 channel.on_data do |ch, data| 105 110 @callback[ch, :out, data] if @callback tools/capistrano/lib/capistrano/configuration/actions/invocation.rb
r6947 r7387 24 24 initialize_without_invocation(*args) 25 25 set :default_environment, {} 26 set :default_run_options, {} 26 27 end 27 28 … … 111 112 # it will be used. Otherwise, no :shell key is added. 112 113 def add_default_command_options(options) 113 options = options.dup 114 defaults = self[:default_run_options] 115 options = defaults.merge(options) 114 116 115 117 env = self[:default_environment] tools/capistrano/test/command_test.rb
r7145 r7387 20 20 end 21 21 22 def test_command_with_pty_should_request_pty_and_register_success_callback 23 session = setup_for_extracting_channel_action(:on_success) do |ch| 24 ch.expects(:request_pty).with(:want_reply => true) 25 ch.expects(:exec).with(%(sh -c "ls")) 26 end 27 Capistrano::Command.new("ls", [session], :pty => true) 28 end 29 22 30 def test_command_with_env_key_should_have_environment_constructed_and_prepended 23 session = setup_for_extracting_channel_action(:on_success) do |ch| 31 session = setup_for_extracting_channel_action do |ch| 32 ch.expects(:request_pty).never 24 33 ch.expects(:exec).with(%(env FOO=bar sh -c "ls")) 25 34 end … … 28 37 29 38 def test_env_with_symbolic_key_should_be_accepted_as_a_string 30 session = setup_for_extracting_channel_action (:on_success)do |ch|39 session = setup_for_extracting_channel_action do |ch| 31 40 ch.expects(:exec).with(%(env FOO=bar sh -c "ls")) 32 41 end … … 35 44 36 45 def test_env_as_string_should_be_substituted_in_directly 37 session = setup_for_extracting_channel_action (:on_success)do |ch|46 session = setup_for_extracting_channel_action do |ch| 38 47 ch.expects(:exec).with(%(env HOWDY=there sh -c "ls")) 39 48 end … … 42 51 43 52 def test_env_with_symbolic_value_should_be_accepted_as_string 44 session = setup_for_extracting_channel_action (:on_success)do |ch|53 session = setup_for_extracting_channel_action do |ch| 45 54 ch.expects(:exec).with(%(env FOO=bar sh -c "ls")) 46 55 end … … 49 58 50 59 def test_env_value_should_be_escaped 51 session = setup_for_extracting_channel_action (:on_success)do |ch|60 session = setup_for_extracting_channel_action do |ch| 52 61 ch.expects(:exec).with(%(env FOO=(\\ \\\"bar\\\"\\ ) sh -c "ls")) 53 62 end … … 56 65 57 66 def test_env_with_multiple_keys_should_chain_the_entries_together 58 session = setup_for_extracting_channel_action (:on_success)do |ch|67 session = setup_for_extracting_channel_action do |ch| 59 68 ch.expects(:exec).with do |command| 60 69 command =~ /^env / && … … 74 83 session.expects(:open_channel).yields(channel) 75 84 channel.expects(:[]=).with(:host, "capistrano") 85 channel.stubs(:[]).with(:host).returns("capistrano") 76 86 77 87 Capistrano::Command.new("ls", [session]) … … 84 94 session.expects(:open_channel).yields(channel) 85 95 channel.expects(:[]=).with(:options, {:data => "here we go"}) 96 channel.stubs(:[]).with(:host).returns("capistrano") 86 97 87 98 Capistrano::Command.new("ls", [session], :data => "here we go") 88 99 end 89 100 90 def test_open_channel_should_request_pty 91 session = mock(:xserver => server("capistrano")) 92 channel = stub_everything 93 94 session.expects(:open_channel).yields(channel) 95 channel.expects(:request_pty).with(:want_reply => true) 96 101 def test_successful_channel_should_send_command 102 session = setup_for_extracting_channel_action do |ch| 103 ch.expects(:exec).with(%(sh -c "ls")) 104 end 97 105 Capistrano::Command.new("ls", [session]) 98 106 end 99 107 100 def test_successful_channel_should_send_command101 session = setup_for_extracting_channel_action(:on_success) do |ch|102 ch.expects(:exec).with(%(sh -c "ls"))103 end104 Capistrano::Command.new("ls", [session])105 end106 107 108 def test_successful_channel_with_shell_option_should_send_command_via_specified_shell 108 session = setup_for_extracting_channel_action (:on_success)do |ch|109 session = setup_for_extracting_channel_action do |ch| 109 110 ch.expects(:exec).with(%(/bin/bash -c "ls")) 110 111 end … … 113 114 114 115 def test_successful_channel_should_send_data_if_data_key_is_present 115 session = setup_for_extracting_channel_action (:on_success)do |ch|116 session = setup_for_extracting_channel_action do |ch| 116 117 ch.expects(:exec).with(%(sh -c "ls")) 117 118 ch.expects(:send_data).with("here we go") … … 120 121 end 121 122 122 def test_unsuccessful_ channel_should_close_channel123 def test_unsuccessful_pty_request_should_close_channel 123 124 session = setup_for_extracting_channel_action(:on_failure) do |ch| 124 125 ch.expects(:close) 125 126 end 126 Capistrano::Command.new("ls", [session] )127 Capistrano::Command.new("ls", [session], :pty => true) 127 128 end 128 129 … … 259 260 260 261 def test_process_with_host_placeholder_should_substitute_placeholder_with_each_host 261 session = setup_for_extracting_channel_action (:on_success)do |ch|262 session = setup_for_extracting_channel_action do |ch| 262 263 ch.expects(:exec).with(%(sh -c "echo capistrano")) 263 264 end … … 266 267 267 268 def test_process_with_unknown_placeholder_should_not_replace_placeholder 268 session = setup_for_extracting_channel_action (:on_success)do |ch|269 session = setup_for_extracting_channel_action do |ch| 269 270 ch.expects(:exec).with(%(sh -c "echo \\$CAPISTRANO:OTHER\\$")) 270 271 end … … 284 285 end 285 286 286 def setup_for_extracting_channel_action(action , *args)287 def setup_for_extracting_channel_action(action=nil, *args) 287 288 s = server("capistrano") 288 289 session = mock("session", :xserver => s) … … 291 292 session.expects(:open_channel).yields(channel) 292 293 293 ch = mock 294 ch.stubs(:[]).with(:server).returns(s) 295 ch.stubs(:[]).with(:host).returns(s.host) 296 channel.expects(action).yields(ch, *args) 297 298 yield ch if block_given? 294 channel.stubs(:[]).with(:server).returns(s) 295 channel.stubs(:[]).with(:host).returns(s.host) 296 channel.expects(action).yields(channel, *args) if action 297 298 yield channel if block_given? 299 299 300 300 session