mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Makes Capistrano respect dry_run in file transfers
If cap is called with -n capistrano now doesn't transfer any files to and from the server, but logs the action instead.
This commit is contained in:
parent
aa2302061a
commit
5603cc765b
3 changed files with 30 additions and 4 deletions
|
@ -37,7 +37,11 @@ module Capistrano
|
|||
def transfer(direction, from, to, options={}, &block)
|
||||
execute_on_servers(options) do |servers|
|
||||
targets = servers.map { |s| sessions[s] }
|
||||
Transfer.process(direction, from, to, targets, options.merge(:logger => logger), &block)
|
||||
if dry_run
|
||||
logger.debug "transfering: #{[direction, from, to, targets, options.merge(:logger => logger).inspect ] * ', '}"
|
||||
else
|
||||
Transfer.process(direction, from, to, targets, options.merge(:logger => logger), &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'capistrano/configuration/actions/file_transfer'
|
|||
class ConfigurationActionsFileTransferTest < Test::Unit::TestCase
|
||||
class MockConfig
|
||||
include Capistrano::Configuration::Actions::FileTransfer
|
||||
attr_accessor :sessions
|
||||
attr_accessor :sessions, :dry_run
|
||||
end
|
||||
|
||||
def setup
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require "utils"
|
||||
require 'capistrano/configuration/actions/invocation'
|
||||
require 'capistrano/configuration/actions/file_transfer'
|
||||
|
||||
class ConfigurationActionsInvocationTest < Test::Unit::TestCase
|
||||
class MockConfig
|
||||
|
@ -7,9 +8,11 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
|
|||
attr_accessor :debug
|
||||
attr_accessor :dry_run
|
||||
attr_accessor :preserve_roles
|
||||
attr_accessor :servers
|
||||
|
||||
def initialize
|
||||
@options = {}
|
||||
@servers = []
|
||||
end
|
||||
|
||||
def [](*args)
|
||||
|
@ -24,13 +27,17 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
|
|||
@options.fetch(*args)
|
||||
end
|
||||
|
||||
def execute_on_servers(options = {})
|
||||
yield @servers
|
||||
end
|
||||
|
||||
include Capistrano::Configuration::Actions::Invocation
|
||||
include Capistrano::Configuration::Actions::FileTransfer
|
||||
end
|
||||
|
||||
def setup
|
||||
@config = MockConfig.new
|
||||
@config = make_config
|
||||
@original_io_proc = MockConfig.default_io_proc
|
||||
@config.stubs(:logger).returns(stub_everything)
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
@ -48,6 +55,15 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
|
|||
@config.run "ls", :foo => "bar"
|
||||
end
|
||||
|
||||
def test_put_wont_transfer_if_dry_run
|
||||
config = make_config
|
||||
config.dry_run = true
|
||||
config.servers = %w[ foo ]
|
||||
config.expects(:sessions).returns({ 'foo-server' => 'bar' })
|
||||
::Capistrano::Transfer.expects(:process).never
|
||||
config.put "foo", "bar", :mode => 0644
|
||||
end
|
||||
|
||||
def test_add_default_command_options_should_return_bare_options_if_there_is_no_env_or_shell_specified
|
||||
assert_equal({:foo => "bar"}, @config.add_default_command_options(:foo => "bar"))
|
||||
end
|
||||
|
@ -203,6 +219,12 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
|
|||
|
||||
private
|
||||
|
||||
def make_config
|
||||
config = MockConfig.new
|
||||
config.stubs(:logger).returns(stub_everything)
|
||||
config
|
||||
end
|
||||
|
||||
def inspectable_proc
|
||||
Proc.new do |ch, stream, data|
|
||||
ch.called
|
||||
|
|
Loading…
Add table
Reference in a new issue