capistrano 2.15.11 → 3.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +17 -8
- data/Gemfile +1 -12
- data/LICENSE.txt +18 -0
- data/README.md +65 -68
- data/Rakefile +4 -10
- data/bin/cap +2 -3
- data/bin/capify +7 -91
- data/capistrano.gemspec +20 -34
- data/lib/Capfile +2 -0
- data/lib/capistrano/application.rb +28 -0
- data/lib/capistrano/bundler.rb +1 -0
- data/lib/capistrano/configuration/question.rb +42 -0
- data/lib/capistrano/configuration/server.rb +24 -0
- data/lib/capistrano/configuration/servers.rb +43 -95
- data/lib/capistrano/configuration.rb +81 -44
- data/lib/capistrano/console.rb +1 -0
- data/lib/capistrano/defaults.rb +11 -0
- data/lib/capistrano/deploy.rb +3 -0
- data/lib/capistrano/dotfile.rb +3 -0
- data/lib/capistrano/dsl/env.rb +57 -0
- data/lib/capistrano/dsl/paths.rb +74 -0
- data/lib/capistrano/dsl/stages.rb +15 -0
- data/lib/capistrano/dsl/task_enhancements.rb +15 -0
- data/lib/capistrano/dsl.rb +38 -0
- data/lib/capistrano/git.rb +1 -0
- data/lib/capistrano/i18n.rb +33 -0
- data/lib/capistrano/install.rb +1 -0
- data/lib/capistrano/setup.rb +17 -0
- data/lib/capistrano/tasks/bundler.rake +13 -0
- data/lib/capistrano/tasks/console.rake +21 -0
- data/lib/capistrano/tasks/deploy.rake +153 -0
- data/lib/capistrano/tasks/framework.rake +45 -0
- data/lib/capistrano/tasks/git.rake +65 -0
- data/lib/capistrano/tasks/install.rake +39 -0
- data/lib/capistrano/templates/Capfile +43 -0
- data/lib/capistrano/templates/deploy.rb.erb +17 -0
- data/lib/capistrano/templates/stage.rb.erb +20 -0
- data/lib/capistrano/version.rb +1 -11
- data/lib/capistrano.rb +9 -3
- data/spec/lib/capistrano/configuration/question_spec.rb +54 -0
- data/spec/lib/capistrano/configuration/server_spec.rb +48 -0
- data/spec/lib/capistrano/configuration/servers_spec.rb +79 -0
- data/spec/lib/capistrano/configuration_spec.rb +80 -0
- data/spec/lib/capistrano/dsl/env_spec.rb +83 -0
- data/spec/lib/capistrano/dsl/paths_spec.rb +69 -0
- data/spec/lib/capistrano/dsl_spec.rb +51 -0
- data/spec/lib/capistrano_spec.rb +8 -0
- data/spec/spec_helper.rb +14 -0
- metadata +89 -215
- data/.travis.yml +0 -9
- data/CHANGELOG +0 -1203
- data/lib/capistrano/callback.rb +0 -45
- data/lib/capistrano/cli/execute.rb +0 -85
- data/lib/capistrano/cli/help.rb +0 -125
- data/lib/capistrano/cli/help.txt +0 -81
- data/lib/capistrano/cli/options.rb +0 -243
- data/lib/capistrano/cli/ui.rb +0 -40
- data/lib/capistrano/cli.rb +0 -47
- data/lib/capistrano/command.rb +0 -303
- data/lib/capistrano/configuration/actions/file_transfer.rb +0 -50
- data/lib/capistrano/configuration/actions/inspect.rb +0 -46
- data/lib/capistrano/configuration/actions/invocation.rb +0 -329
- data/lib/capistrano/configuration/alias_task.rb +0 -26
- data/lib/capistrano/configuration/callbacks.rb +0 -147
- data/lib/capistrano/configuration/connections.rb +0 -237
- data/lib/capistrano/configuration/execution.rb +0 -142
- data/lib/capistrano/configuration/loading.rb +0 -205
- data/lib/capistrano/configuration/log_formatters.rb +0 -75
- data/lib/capistrano/configuration/namespaces.rb +0 -223
- data/lib/capistrano/configuration/roles.rb +0 -83
- data/lib/capistrano/configuration/variables.rb +0 -127
- data/lib/capistrano/errors.rb +0 -19
- data/lib/capistrano/ext/multistage.rb +0 -67
- data/lib/capistrano/ext/string.rb +0 -5
- data/lib/capistrano/extensions.rb +0 -57
- data/lib/capistrano/fix_rake_deprecated_dsl.rb +0 -8
- data/lib/capistrano/logger.rb +0 -166
- data/lib/capistrano/processable.rb +0 -55
- data/lib/capistrano/recipes/compat.rb +0 -32
- data/lib/capistrano/recipes/deploy/assets.rb +0 -202
- data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
- data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -54
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -117
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
- data/lib/capistrano/recipes/deploy/scm/base.rb +0 -200
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -153
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -96
- data/lib/capistrano/recipes/deploy/scm/git.rb +0 -299
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -137
- data/lib/capistrano/recipes/deploy/scm/none.rb +0 -55
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -152
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -121
- data/lib/capistrano/recipes/deploy/scm.rb +0 -19
- data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -92
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -338
- data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -57
- data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +0 -21
- data/lib/capistrano/recipes/deploy/strategy.rb +0 -20
- data/lib/capistrano/recipes/deploy.rb +0 -625
- data/lib/capistrano/recipes/standard.rb +0 -37
- data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
- data/lib/capistrano/role.rb +0 -102
- data/lib/capistrano/server_definition.rb +0 -56
- data/lib/capistrano/shell.rb +0 -265
- data/lib/capistrano/ssh.rb +0 -95
- data/lib/capistrano/task_definition.rb +0 -77
- data/lib/capistrano/transfer.rb +0 -218
- data/test/cli/execute_test.rb +0 -132
- data/test/cli/help_test.rb +0 -165
- data/test/cli/options_test.rb +0 -329
- data/test/cli/ui_test.rb +0 -28
- data/test/cli_test.rb +0 -17
- data/test/command_test.rb +0 -322
- data/test/configuration/actions/file_transfer_test.rb +0 -61
- data/test/configuration/actions/inspect_test.rb +0 -76
- data/test/configuration/actions/invocation_test.rb +0 -306
- data/test/configuration/alias_task_test.rb +0 -118
- data/test/configuration/callbacks_test.rb +0 -201
- data/test/configuration/connections_test.rb +0 -439
- data/test/configuration/execution_test.rb +0 -175
- data/test/configuration/loading_test.rb +0 -148
- data/test/configuration/namespace_dsl_test.rb +0 -332
- data/test/configuration/roles_test.rb +0 -157
- data/test/configuration/servers_test.rb +0 -183
- data/test/configuration/variables_test.rb +0 -190
- data/test/configuration_test.rb +0 -77
- data/test/deploy/local_dependency_test.rb +0 -76
- data/test/deploy/remote_dependency_test.rb +0 -146
- data/test/deploy/scm/accurev_test.rb +0 -23
- data/test/deploy/scm/base_test.rb +0 -55
- data/test/deploy/scm/bzr_test.rb +0 -51
- data/test/deploy/scm/darcs_test.rb +0 -37
- data/test/deploy/scm/git_test.rb +0 -274
- data/test/deploy/scm/mercurial_test.rb +0 -134
- data/test/deploy/scm/none_test.rb +0 -35
- data/test/deploy/scm/perforce_test.rb +0 -23
- data/test/deploy/scm/subversion_test.rb +0 -68
- data/test/deploy/strategy/copy_test.rb +0 -360
- data/test/extensions_test.rb +0 -69
- data/test/fixtures/cli_integration.rb +0 -5
- data/test/fixtures/config.rb +0 -5
- data/test/fixtures/custom.rb +0 -3
- data/test/logger_formatting_test.rb +0 -149
- data/test/logger_test.rb +0 -134
- data/test/recipes_test.rb +0 -25
- data/test/role_test.rb +0 -11
- data/test/server_definition_test.rb +0 -121
- data/test/shell_test.rb +0 -96
- data/test/ssh_test.rb +0 -113
- data/test/task_definition_test.rb +0 -117
- data/test/transfer_test.rb +0 -168
- data/test/utils.rb +0 -37
- data/test/version_test.rb +0 -11
@@ -1,61 +0,0 @@
|
|
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
|
@@ -1,76 +0,0 @@
|
|
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
|
@@ -1,306 +0,0 @@
|
|
1
|
-
require "utils"
|
2
|
-
require 'capistrano/configuration/actions/invocation'
|
3
|
-
require 'capistrano/configuration/actions/file_transfer'
|
4
|
-
|
5
|
-
class ConfigurationActionsInvocationTest < Test::Unit::TestCase
|
6
|
-
class MockConfig
|
7
|
-
attr_reader :options
|
8
|
-
attr_accessor :debug
|
9
|
-
attr_accessor :dry_run
|
10
|
-
attr_accessor :preserve_roles
|
11
|
-
attr_accessor :servers
|
12
|
-
attr_accessor :roles
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@options = {}
|
16
|
-
@servers = []
|
17
|
-
end
|
18
|
-
|
19
|
-
def [](*args)
|
20
|
-
@options[*args]
|
21
|
-
end
|
22
|
-
|
23
|
-
def set(name, value)
|
24
|
-
@options[name] = value
|
25
|
-
end
|
26
|
-
|
27
|
-
def fetch(*args)
|
28
|
-
@options.fetch(*args)
|
29
|
-
end
|
30
|
-
|
31
|
-
def filter_servers(options = {})
|
32
|
-
[nil, @servers]
|
33
|
-
end
|
34
|
-
|
35
|
-
def execute_on_servers(options = {})
|
36
|
-
yield @servers
|
37
|
-
end
|
38
|
-
|
39
|
-
include Capistrano::Configuration::Actions::Invocation
|
40
|
-
include Capistrano::Configuration::Actions::FileTransfer
|
41
|
-
end
|
42
|
-
|
43
|
-
def setup
|
44
|
-
@config = make_config
|
45
|
-
@original_io_proc = MockConfig.default_io_proc
|
46
|
-
end
|
47
|
-
|
48
|
-
def teardown
|
49
|
-
MockConfig.default_io_proc = @original_io_proc
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_run_options_should_be_passed_to_execute_on_servers
|
53
|
-
@config.expects(:execute_on_servers).with(:foo => "bar", :eof => true)
|
54
|
-
@config.run "ls", :foo => "bar"
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_run_will_return_if_dry_run
|
58
|
-
@config.expects(:dry_run).returns(true)
|
59
|
-
@config.expects(:execute_on_servers).never
|
60
|
-
@config.run "ls", :foo => "bar"
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_put_wont_transfer_if_dry_run
|
64
|
-
config = make_config
|
65
|
-
config.dry_run = true
|
66
|
-
config.servers = %w[ foo ]
|
67
|
-
config.expects(:execute_on_servers).never
|
68
|
-
::Capistrano::Transfer.expects(:process).never
|
69
|
-
config.put "foo", "bar", :mode => 0644
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_add_default_command_options_should_return_bare_options_if_there_is_no_env_or_shell_specified
|
73
|
-
assert_equal({:foo => "bar"}, @config.add_default_command_options(:foo => "bar"))
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_add_default_command_options_should_merge_default_environment_as_env
|
77
|
-
@config[:default_environment][:bang] = "baz"
|
78
|
-
assert_equal({:foo => "bar", :env => { :bang => "baz" }}, @config.add_default_command_options(:foo => "bar"))
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_add_default_command_options_should_merge_env_with_default_environment
|
82
|
-
@config[:default_environment][:bang] = "baz"
|
83
|
-
@config[:default_environment][:bacon] = "crunchy"
|
84
|
-
assert_equal({:foo => "bar", :env => { :bang => "baz", :bacon => "chunky", :flip => "flop" }}, @config.add_default_command_options(:foo => "bar", :env => {:bacon => "chunky", :flip => "flop"}))
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_add_default_command_options_should_use_default_shell_if_present
|
88
|
-
@config.set :default_shell, "/bin/bash"
|
89
|
-
assert_equal({:foo => "bar", :shell => "/bin/bash"}, @config.add_default_command_options(:foo => "bar"))
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_add_default_command_options_should_use_default_shell_of_false_if_present
|
93
|
-
@config.set :default_shell, false
|
94
|
-
assert_equal({:foo => "bar", :shell => false}, @config.add_default_command_options(:foo => "bar"))
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_add_default_command_options_should_use_shell_in_preference_of_default_shell
|
98
|
-
@config.set :default_shell, "/bin/bash"
|
99
|
-
assert_equal({:foo => "bar", :shell => "/bin/sh"}, @config.add_default_command_options(:foo => "bar", :shell => "/bin/sh"))
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_default_io_proc_should_log_stdout_arguments_as_info
|
103
|
-
ch = { :host => "capistrano",
|
104
|
-
:server => server("capistrano"),
|
105
|
-
:options => { :logger => mock("logger") } }
|
106
|
-
ch[:options][:logger].expects(:info).with("data stuff", "out :: capistrano")
|
107
|
-
MockConfig.default_io_proc[ch, :out, "data stuff"]
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_default_io_proc_should_log_stderr_arguments_as_important
|
111
|
-
ch = { :host => "capistrano",
|
112
|
-
:server => server("capistrano"),
|
113
|
-
:options => { :logger => mock("logger") } }
|
114
|
-
ch[:options][:logger].expects(:important).with("data stuff", "err :: capistrano")
|
115
|
-
MockConfig.default_io_proc[ch, :err, "data stuff"]
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_sudo_should_default_to_sudo
|
119
|
-
@config.expects(:run).with("sudo -p 'sudo password: ' ls", {})
|
120
|
-
@config.sudo "ls"
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_sudo_should_keep_input_stream_open
|
124
|
-
@config.expects(:execute_on_servers).with(:foo => "bar")
|
125
|
-
@config.sudo "ls", :foo => "bar"
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_sudo_should_use_sudo_variable_definition
|
129
|
-
@config.expects(:run).with("/opt/local/bin/sudo -p 'sudo password: ' ls", {})
|
130
|
-
@config.options[:sudo] = "/opt/local/bin/sudo"
|
131
|
-
@config.sudo "ls"
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_sudo_should_interpret_as_option_as_user
|
135
|
-
@config.expects(:run).with("sudo -p 'sudo password: ' -u app ls", {})
|
136
|
-
@config.sudo "ls", :as => "app"
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_sudo_should_pass_options_through_to_run
|
140
|
-
@config.expects(:run).with("sudo -p 'sudo password: ' ls", :foo => "bar")
|
141
|
-
@config.sudo "ls", :foo => "bar"
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_sudo_should_avoid_minus_p_when_sudo_prompt_is_empty
|
145
|
-
@config.set :sudo_prompt, ""
|
146
|
-
@config.expects(:run).with("sudo ls", {})
|
147
|
-
@config.sudo "ls"
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_sudo_should_interpret_sudo_prompt_variable_as_custom_prompt
|
151
|
-
@config.set :sudo_prompt, "give it to me: "
|
152
|
-
@config.expects(:run).with("sudo -p 'give it to me: ' ls", {})
|
153
|
-
@config.sudo "ls"
|
154
|
-
end
|
155
|
-
|
156
|
-
def test_sudo_behavior_callback_should_send_password_when_prompted_with_default_sudo_prompt
|
157
|
-
ch = mock("channel")
|
158
|
-
ch.expects(:send_data).with("g00b3r\n")
|
159
|
-
@config.options[:password] = "g00b3r"
|
160
|
-
@config.sudo_behavior_callback(nil)[ch, nil, "sudo password: "]
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_sudo_behavior_callback_should_send_password_when_prompted_with_custom_sudo_prompt
|
164
|
-
ch = mock("channel")
|
165
|
-
ch.expects(:send_data).with("g00b3r\n")
|
166
|
-
@config.set :sudo_prompt, "give it to me: "
|
167
|
-
@config.options[:password] = "g00b3r"
|
168
|
-
@config.sudo_behavior_callback(nil)[ch, nil, "give it to me: "]
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_sudo_behavior_callback_with_incorrect_password_on_first_prompt
|
172
|
-
ch = mock("channel")
|
173
|
-
ch.stubs(:[]).with(:host).returns("capistrano")
|
174
|
-
ch.stubs(:[]).with(:server).returns(server("capistrano"))
|
175
|
-
@config.expects(:reset!).with(:password)
|
176
|
-
@config.sudo_behavior_callback(nil)[ch, nil, "Sorry, try again."]
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_sudo_behavior_callback_with_incorrect_password_on_subsequent_prompts
|
180
|
-
callback = @config.sudo_behavior_callback(nil)
|
181
|
-
|
182
|
-
ch = mock("channel")
|
183
|
-
ch.stubs(:[]).with(:host).returns("capistrano")
|
184
|
-
ch.stubs(:[]).with(:server).returns(server("capistrano"))
|
185
|
-
ch2 = mock("channel")
|
186
|
-
ch2.stubs(:[]).with(:host).returns("cap2")
|
187
|
-
ch2.stubs(:[]).with(:server).returns(server("cap2"))
|
188
|
-
|
189
|
-
@config.expects(:reset!).with(:password).times(2)
|
190
|
-
|
191
|
-
callback[ch, nil, "Sorry, try again."]
|
192
|
-
callback[ch2, nil, "Sorry, try again."] # shouldn't call reset!
|
193
|
-
callback[ch, nil, "Sorry, try again."]
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_sudo_behavior_callback_should_reset_password_and_prompt_again_if_output_includes_both_cues
|
197
|
-
ch = mock("channel")
|
198
|
-
ch.stubs(:[]).with(:host).returns("capistrano")
|
199
|
-
ch.stubs(:[]).with(:server).returns(server("capistrano"))
|
200
|
-
ch.expects(:send_data, "password!\n").times(2)
|
201
|
-
|
202
|
-
@config.set(:password, "password!")
|
203
|
-
@config.expects(:reset!).with(:password)
|
204
|
-
|
205
|
-
callback = @config.sudo_behavior_callback(nil)
|
206
|
-
callback[ch, :out, "sudo password: "]
|
207
|
-
callback[ch, :out, "Sorry, try again.\nsudo password: "]
|
208
|
-
end
|
209
|
-
|
210
|
-
def test_sudo_behavior_callback_should_defer_to_fallback_for_other_output
|
211
|
-
callback = @config.sudo_behavior_callback(inspectable_proc)
|
212
|
-
|
213
|
-
a = mock("channel", :called => true)
|
214
|
-
b = mock("stream", :called => true)
|
215
|
-
c = mock("data", :called => true)
|
216
|
-
|
217
|
-
callback[a, b, c]
|
218
|
-
end
|
219
|
-
|
220
|
-
def test_invoke_command_should_default_to_run
|
221
|
-
@config.expects(:run).with("ls", :once => true)
|
222
|
-
@config.invoke_command("ls", :once => true)
|
223
|
-
end
|
224
|
-
|
225
|
-
def test_invoke_command_should_delegate_to_method_identified_by_via
|
226
|
-
@config.expects(:foobar).with("ls", :once => true)
|
227
|
-
@config.invoke_command("ls", :once => true, :via => :foobar)
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_parallel_command_execution_with_no_match
|
231
|
-
assert_block("should not raise argument error") do
|
232
|
-
begin
|
233
|
-
@config.parallel do |session|
|
234
|
-
session.when("in?(:app)", "ls") {|ch,stream,data| puts "noop"}
|
235
|
-
session.when("in?(:db)", "pwd") {|ch,stream,data| puts "noop"}
|
236
|
-
end
|
237
|
-
true
|
238
|
-
rescue
|
239
|
-
false
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
def test_parallel_command_execution_with_matching_servers
|
245
|
-
@config.expects(:execute_on_servers)
|
246
|
-
|
247
|
-
logger = mock('logger')
|
248
|
-
logger.stubs(:debug).with("executing multiple commands in parallel").once
|
249
|
-
logger.stubs(:trace).twice
|
250
|
-
@config.stubs(:logger).returns(logger)
|
251
|
-
|
252
|
-
assert_block("should not raise Argument error") do
|
253
|
-
begin
|
254
|
-
@config.servers = [:app, :db]
|
255
|
-
@config.roles = {:app => [:app], :db => [:db] }
|
256
|
-
@config.parallel do |session|
|
257
|
-
session.when("in?(:app)", "ls") {|ch,stream,data| puts "noop"}
|
258
|
-
session.when("in?(:db)", "pwd") {|ch,stream,data| puts "noop"}
|
259
|
-
end
|
260
|
-
true
|
261
|
-
rescue
|
262
|
-
false
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
def test_run_only_logs_once
|
268
|
-
@config.servers = [:app, :db]
|
269
|
-
|
270
|
-
logger = mock('logger')
|
271
|
-
logger.stubs(:debug).with("executing \"ls\"")
|
272
|
-
@config.stubs(:logger).returns(logger)
|
273
|
-
|
274
|
-
@config.expects(:execute_on_servers)
|
275
|
-
|
276
|
-
@config.run("ls")
|
277
|
-
end
|
278
|
-
|
279
|
-
private
|
280
|
-
|
281
|
-
def make_config
|
282
|
-
config = MockConfig.new
|
283
|
-
config.stubs(:logger).returns(stub_everything)
|
284
|
-
config
|
285
|
-
end
|
286
|
-
|
287
|
-
def inspectable_proc
|
288
|
-
Proc.new do |ch, stream, data|
|
289
|
-
ch.called
|
290
|
-
stream.called
|
291
|
-
data.called
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
def prepare_command(command, sessions, options)
|
296
|
-
a = mock("channel", :called => true)
|
297
|
-
b = mock("stream", :called => true)
|
298
|
-
c = mock("data", :called => true)
|
299
|
-
|
300
|
-
compare_args = Proc.new do |tree, sess, opts|
|
301
|
-
tree.fallback.command == command && sess == sessions && opts == options
|
302
|
-
end
|
303
|
-
|
304
|
-
Capistrano::Command.expects(:process).with(&compare_args)
|
305
|
-
end
|
306
|
-
end
|
@@ -1,118 +0,0 @@
|
|
1
|
-
require 'utils'
|
2
|
-
require 'capistrano/configuration/alias_task'
|
3
|
-
require 'capistrano/configuration/execution'
|
4
|
-
require 'capistrano/configuration/namespaces'
|
5
|
-
require 'capistrano/task_definition'
|
6
|
-
|
7
|
-
class AliasTaskTest < Test::Unit::TestCase
|
8
|
-
class MockConfig
|
9
|
-
attr_reader :options
|
10
|
-
attr_accessor :logger
|
11
|
-
|
12
|
-
def initialize(options={})
|
13
|
-
@options = {}
|
14
|
-
@logger = options.delete(:logger)
|
15
|
-
end
|
16
|
-
|
17
|
-
include Capistrano::Configuration::AliasTask
|
18
|
-
include Capistrano::Configuration::Execution
|
19
|
-
include Capistrano::Configuration::Namespaces
|
20
|
-
end
|
21
|
-
|
22
|
-
def setup
|
23
|
-
@config = MockConfig.new( :logger => stub(:debug => nil, :info => nil, :important => nil) )
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_makes_a_copy_of_the_task
|
27
|
-
@config.task(:foo) { 42 }
|
28
|
-
@config.alias_task 'new_foo', 'foo'
|
29
|
-
|
30
|
-
assert @config.tasks.key?(:new_foo)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_original_task_remain_with_same_name
|
34
|
-
@config.task(:foo) { 42 }
|
35
|
-
@config.alias_task 'new_foo', 'foo'
|
36
|
-
|
37
|
-
assert_equal :foo, @config.tasks[:foo].name
|
38
|
-
assert_equal :new_foo, @config.tasks[:new_foo].name
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_aliased_task_do_the_same
|
42
|
-
@config.task(:foo) { 42 }
|
43
|
-
@config.alias_task 'new_foo', 'foo'
|
44
|
-
|
45
|
-
assert_equal 42, @config.find_and_execute_task('new_foo')
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_aliased_task_should_preserve_description
|
49
|
-
@config.task(:foo, :desc => "the Ultimate Question of Life, the Universe, and Everything" ) { 42 }
|
50
|
-
@config.alias_task 'new_foo', 'foo'
|
51
|
-
|
52
|
-
task = @config.find_task('foo')
|
53
|
-
new_task = @config.find_task('new_foo')
|
54
|
-
|
55
|
-
assert_equal task.description, new_task.description
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_aliased_task_should_preserve_on_error
|
59
|
-
@config.task(:foo, :on_error => :continue) { 42 }
|
60
|
-
@config.alias_task 'new_foo', 'foo'
|
61
|
-
|
62
|
-
task = @config.find_task('foo')
|
63
|
-
new_task = @config.find_task('new_foo')
|
64
|
-
|
65
|
-
assert_equal task.on_error, new_task.on_error
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_aliased_task_should_preserve_max_hosts
|
69
|
-
@config.task(:foo, :max_hosts => 5) { 42 }
|
70
|
-
@config.alias_task 'new_foo', 'foo'
|
71
|
-
|
72
|
-
task = @config.find_task('foo')
|
73
|
-
new_task = @config.find_task('new_foo')
|
74
|
-
|
75
|
-
assert_equal task.max_hosts, new_task.max_hosts
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_raise_exception_when_task_doesnt_exist
|
79
|
-
assert_raises(Capistrano::NoSuchTaskError) { @config.alias_task 'non_existant_task', 'fail_miserably' }
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_convert_task_names_using_to_str
|
83
|
-
@config.task(:foo, :role => :app) { 42 }
|
84
|
-
|
85
|
-
@config.alias_task 'one', 'foo'
|
86
|
-
@config.alias_task :two, 'foo'
|
87
|
-
@config.alias_task 'three', :foo
|
88
|
-
@config.alias_task :four, :foo
|
89
|
-
|
90
|
-
assert @config.tasks.key?(:one)
|
91
|
-
assert @config.tasks.key?(:two)
|
92
|
-
assert @config.tasks.key?(:three)
|
93
|
-
assert @config.tasks.key?(:four)
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_raise_an_exception_when_task_names_can_not_be_converted
|
97
|
-
@config.task(:foo, :role => :app) { 42 }
|
98
|
-
|
99
|
-
assert_raises(ArgumentError) { @config.alias_task mock('x'), :foo }
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_should_include_namespace
|
103
|
-
@config.namespace(:outer) do
|
104
|
-
task(:foo) { 42 }
|
105
|
-
alias_task 'new_foo', 'foo'
|
106
|
-
|
107
|
-
namespace(:inner) do
|
108
|
-
task(:foo) { 43 }
|
109
|
-
alias_task 'new_foo', 'foo'
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
assert_equal 42, @config.find_and_execute_task('outer:new_foo')
|
114
|
-
assert_equal 42, @config.find_and_execute_task('outer:foo')
|
115
|
-
assert_equal 43, @config.find_and_execute_task('outer:inner:new_foo')
|
116
|
-
assert_equal 43, @config.find_and_execute_task('outer:inner:foo')
|
117
|
-
end
|
118
|
-
end
|