minmb-capistrano 2.15.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.travis.yml +7 -0
- data/CHANGELOG +1170 -0
- data/Gemfile +13 -0
- data/README.md +94 -0
- data/Rakefile +11 -0
- data/bin/cap +4 -0
- data/bin/capify +92 -0
- data/capistrano.gemspec +40 -0
- data/lib/capistrano.rb +5 -0
- data/lib/capistrano/callback.rb +45 -0
- data/lib/capistrano/cli.rb +47 -0
- data/lib/capistrano/cli/execute.rb +85 -0
- data/lib/capistrano/cli/help.rb +125 -0
- data/lib/capistrano/cli/help.txt +81 -0
- data/lib/capistrano/cli/options.rb +243 -0
- data/lib/capistrano/cli/ui.rb +40 -0
- data/lib/capistrano/command.rb +303 -0
- data/lib/capistrano/configuration.rb +57 -0
- data/lib/capistrano/configuration/actions/file_transfer.rb +50 -0
- data/lib/capistrano/configuration/actions/inspect.rb +46 -0
- data/lib/capistrano/configuration/actions/invocation.rb +329 -0
- data/lib/capistrano/configuration/alias_task.rb +26 -0
- data/lib/capistrano/configuration/callbacks.rb +147 -0
- data/lib/capistrano/configuration/connections.rb +237 -0
- data/lib/capistrano/configuration/execution.rb +142 -0
- data/lib/capistrano/configuration/loading.rb +205 -0
- data/lib/capistrano/configuration/log_formatters.rb +75 -0
- data/lib/capistrano/configuration/namespaces.rb +223 -0
- data/lib/capistrano/configuration/roles.rb +77 -0
- data/lib/capistrano/configuration/servers.rb +116 -0
- data/lib/capistrano/configuration/variables.rb +127 -0
- data/lib/capistrano/errors.rb +19 -0
- data/lib/capistrano/ext/multistage.rb +64 -0
- data/lib/capistrano/ext/string.rb +5 -0
- data/lib/capistrano/extensions.rb +57 -0
- data/lib/capistrano/fix_rake_deprecated_dsl.rb +8 -0
- data/lib/capistrano/logger.rb +166 -0
- data/lib/capistrano/processable.rb +57 -0
- data/lib/capistrano/recipes/compat.rb +32 -0
- data/lib/capistrano/recipes/deploy.rb +625 -0
- data/lib/capistrano/recipes/deploy/assets.rb +201 -0
- data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
- data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +117 -0
- data/lib/capistrano/recipes/deploy/scm.rb +19 -0
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
- data/lib/capistrano/recipes/deploy/scm/base.rb +200 -0
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +153 -0
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +96 -0
- data/lib/capistrano/recipes/deploy/scm/git.rb +293 -0
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
- data/lib/capistrano/recipes/deploy/scm/none.rb +55 -0
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +152 -0
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
- data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
- data/lib/capistrano/recipes/deploy/strategy/base.rb +92 -0
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +338 -0
- data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +57 -0
- data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +21 -0
- data/lib/capistrano/recipes/standard.rb +37 -0
- data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/role.rb +102 -0
- data/lib/capistrano/server_definition.rb +56 -0
- data/lib/capistrano/shell.rb +265 -0
- data/lib/capistrano/ssh.rb +95 -0
- data/lib/capistrano/task_definition.rb +77 -0
- data/lib/capistrano/transfer.rb +218 -0
- data/lib/capistrano/version.rb +11 -0
- data/test/cli/execute_test.rb +132 -0
- data/test/cli/help_test.rb +165 -0
- data/test/cli/options_test.rb +329 -0
- data/test/cli/ui_test.rb +28 -0
- data/test/cli_test.rb +17 -0
- data/test/command_test.rb +322 -0
- data/test/configuration/actions/file_transfer_test.rb +61 -0
- data/test/configuration/actions/inspect_test.rb +76 -0
- data/test/configuration/actions/invocation_test.rb +288 -0
- data/test/configuration/alias_task_test.rb +118 -0
- data/test/configuration/callbacks_test.rb +201 -0
- data/test/configuration/connections_test.rb +439 -0
- data/test/configuration/execution_test.rb +175 -0
- data/test/configuration/loading_test.rb +148 -0
- data/test/configuration/namespace_dsl_test.rb +332 -0
- data/test/configuration/roles_test.rb +157 -0
- data/test/configuration/servers_test.rb +183 -0
- data/test/configuration/variables_test.rb +190 -0
- data/test/configuration_test.rb +77 -0
- data/test/deploy/local_dependency_test.rb +76 -0
- data/test/deploy/remote_dependency_test.rb +146 -0
- data/test/deploy/scm/accurev_test.rb +23 -0
- data/test/deploy/scm/base_test.rb +55 -0
- data/test/deploy/scm/bzr_test.rb +51 -0
- data/test/deploy/scm/darcs_test.rb +37 -0
- data/test/deploy/scm/git_test.rb +221 -0
- data/test/deploy/scm/mercurial_test.rb +134 -0
- data/test/deploy/scm/none_test.rb +35 -0
- data/test/deploy/scm/perforce_test.rb +23 -0
- data/test/deploy/scm/subversion_test.rb +40 -0
- data/test/deploy/strategy/copy_test.rb +360 -0
- data/test/extensions_test.rb +69 -0
- data/test/fixtures/cli_integration.rb +5 -0
- data/test/fixtures/config.rb +5 -0
- data/test/fixtures/custom.rb +3 -0
- data/test/logger_formatting_test.rb +149 -0
- data/test/logger_test.rb +134 -0
- data/test/recipes_test.rb +25 -0
- data/test/role_test.rb +11 -0
- data/test/server_definition_test.rb +121 -0
- data/test/shell_test.rb +96 -0
- data/test/ssh_test.rb +113 -0
- data/test/task_definition_test.rb +117 -0
- data/test/transfer_test.rb +168 -0
- data/test/utils.rb +37 -0
- metadata +316 -0
data/test/logger_test.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/logger'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
class LoggerTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@io = StringIO.new
|
8
|
+
# Turn off formatting for these tests. Formatting is tested in `logger_formatting_test.rb`.
|
9
|
+
@logger = Capistrano::Logger.new(:output => @io, :disable_formatters => true)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_logger_should_use_STDERR_by_default
|
13
|
+
logger = Capistrano::Logger.new
|
14
|
+
assert_equal STDERR, logger.device
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_logger_should_have_log_level_0
|
18
|
+
logger = Capistrano::Logger.new
|
19
|
+
assert_equal 0, logger.level
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_logger_should_use_level_form_options
|
23
|
+
logger = Capistrano::Logger.new :level => 4
|
24
|
+
assert_equal 4, logger.level
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_logger_should_use_output_option_if_output_responds_to_puts
|
28
|
+
logger = Capistrano::Logger.new(:output => STDOUT)
|
29
|
+
assert_equal STDOUT, logger.device
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_logger_should_open_file_if_output_does_not_respond_to_puts
|
33
|
+
File.expects(:open).with("logs/capistrano.log", "a").returns(:mock)
|
34
|
+
logger = Capistrano::Logger.new(:output => "logs/capistrano.log")
|
35
|
+
assert_equal :mock, logger.device
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_close_should_not_close_device_if_device_is_default
|
39
|
+
logger = Capistrano::Logger.new
|
40
|
+
logger.device.expects(:close).never
|
41
|
+
logger.close
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_close_should_not_close_device_is_device_is_explicitly_given
|
45
|
+
logger = Capistrano::Logger.new(:output => STDOUT)
|
46
|
+
STDOUT.expects(:close).never
|
47
|
+
logger.close
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_close_should_close_device_when_device_was_implicitly_opened
|
51
|
+
f = mock("file", :close => nil)
|
52
|
+
File.expects(:open).with("logs/capistrano.log", "a").returns(f)
|
53
|
+
logger = Capistrano::Logger.new(:output => "logs/capistrano.log")
|
54
|
+
logger.close
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_log_with_level_greater_than_threshold_should_ignore_message
|
58
|
+
@logger.level = 3
|
59
|
+
@logger.log(4, "message")
|
60
|
+
assert @io.string.empty?
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_log_with_level_equal_to_threshold_should_log_message
|
64
|
+
@logger.level = 3
|
65
|
+
@logger.log(3, "message")
|
66
|
+
assert @io.string.include?("message")
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_log_with_level_less_than_threshold_should_log_message
|
70
|
+
@logger.level = 3
|
71
|
+
@logger.log(2, "message")
|
72
|
+
assert @io.string.include?("message")
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_log_with_multiline_message_should_log_each_line_separately
|
76
|
+
@logger.log(0, "first line\nsecond line")
|
77
|
+
assert @io.string.include?("*** first line")
|
78
|
+
assert @io.string.include?("*** second line")
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_log_with_line_prefix_should_insert_line_prefix_before_message
|
82
|
+
@logger.log(0, "message", "prefix")
|
83
|
+
assert @io.string.include?("*** [prefix] message")
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_log_with_level_0_should_have_strong_indent
|
87
|
+
@logger.log(0, "message")
|
88
|
+
assert @io.string.match(/^\*\*\* message/)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_log_with_level_1_should_have_weaker_indent
|
92
|
+
@logger.level = 1
|
93
|
+
@logger.log(1, "message")
|
94
|
+
assert @io.string.match(/^ \*\* message/)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_log_with_level_2_should_have_weaker_indent
|
98
|
+
@logger.level = 2
|
99
|
+
@logger.log(2, "message")
|
100
|
+
assert @io.string.match(/^ \* message/)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_log_with_level_3_should_have_weakest_indent
|
104
|
+
@logger.level = 3
|
105
|
+
@logger.log(3, "message")
|
106
|
+
assert @io.string.match(/^ message/)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_important_should_delegate_to_log_with_level_IMPORTANT
|
110
|
+
@logger.expects(:log).with(Capistrano::Logger::IMPORTANT, "message", "prefix")
|
111
|
+
@logger.important("message", "prefix")
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_info_should_delegate_to_log_with_level_INFO
|
115
|
+
@logger.expects(:log).with(Capistrano::Logger::INFO, "message", "prefix")
|
116
|
+
@logger.info("message", "prefix")
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_debug_should_delegate_to_log_with_level_DEBUG
|
120
|
+
@logger.expects(:log).with(Capistrano::Logger::DEBUG, "message", "prefix")
|
121
|
+
@logger.debug("message", "prefix")
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_trace_should_delegate_to_log_with_level_TRACE
|
125
|
+
@logger.expects(:log).with(Capistrano::Logger::TRACE, "message", "prefix")
|
126
|
+
@logger.trace("message", "prefix")
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_ordering_of_levels
|
130
|
+
assert Capistrano::Logger::IMPORTANT < Capistrano::Logger::INFO
|
131
|
+
assert Capistrano::Logger::INFO < Capistrano::Logger::DEBUG
|
132
|
+
assert Capistrano::Logger::DEBUG < Capistrano::Logger::TRACE
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'utils'
|
2
|
+
require 'capistrano/configuration'
|
3
|
+
|
4
|
+
class RecipesTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@config = Capistrano::Configuration.new
|
8
|
+
@config.stubs(:logger).returns(stub_everything)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_current_releases_does_not_cause_error_on_dry_run
|
12
|
+
@config.dry_run = true
|
13
|
+
@config.load 'deploy'
|
14
|
+
@config.load do
|
15
|
+
set :application, "foo"
|
16
|
+
task :dry_run_test do
|
17
|
+
fetch :current_release
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_nothing_raised do
|
22
|
+
@config.dry_run_test
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/role_test.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/role'
|
3
|
+
|
4
|
+
class RoleTest < Test::Unit::TestCase
|
5
|
+
def test_clearing_a_populated_role_should_yield_no_servers
|
6
|
+
role = Capistrano::Role.new("app1.capistrano.test", lambda { |o| "app2.capistrano.test" })
|
7
|
+
assert_equal 2, role.servers.size
|
8
|
+
role.clear
|
9
|
+
assert role.servers.empty?
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/server_definition'
|
3
|
+
|
4
|
+
class ServerDefinitionTest < Test::Unit::TestCase
|
5
|
+
def test_new_without_credentials_or_port_should_set_values_to_defaults
|
6
|
+
server = Capistrano::ServerDefinition.new("www.capistrano.test")
|
7
|
+
assert_equal "www.capistrano.test", server.host
|
8
|
+
assert_nil server.user
|
9
|
+
assert_nil server.port
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_new_with_encoded_user_should_extract_user_and_use_default_port
|
13
|
+
server = Capistrano::ServerDefinition.new("jamis@www.capistrano.test")
|
14
|
+
assert_equal "www.capistrano.test", server.host
|
15
|
+
assert_equal "jamis", server.user
|
16
|
+
assert_nil server.port
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_new_with_encoded_port_should_extract_port_and_use_default_user
|
20
|
+
server = Capistrano::ServerDefinition.new("www.capistrano.test:8080")
|
21
|
+
assert_equal "www.capistrano.test", server.host
|
22
|
+
assert_nil server.user
|
23
|
+
assert_equal 8080, server.port
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_new_with_encoded_user_and_port_should_extract_user_and_port
|
27
|
+
server = Capistrano::ServerDefinition.new("jamis@www.capistrano.test:8080")
|
28
|
+
assert_equal "www.capistrano.test", server.host
|
29
|
+
assert_equal "jamis", server.user
|
30
|
+
assert_equal 8080, server.port
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_new_with_user_as_option_should_use_given_user
|
34
|
+
server = Capistrano::ServerDefinition.new("www.capistrano.test", :user => "jamis")
|
35
|
+
assert_equal "www.capistrano.test", server.host
|
36
|
+
assert_equal "jamis", server.user
|
37
|
+
assert_nil server.port
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_new_with_port_as_option_should_use_given_user
|
41
|
+
server = Capistrano::ServerDefinition.new("www.capistrano.test", :port => 8080)
|
42
|
+
assert_equal "www.capistrano.test", server.host
|
43
|
+
assert_nil server.user
|
44
|
+
assert_equal 8080, server.port
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_encoded_value_should_override_hash_option
|
48
|
+
server = Capistrano::ServerDefinition.new("jamis@www.capistrano.test:8080", :user => "david", :port => 8081)
|
49
|
+
assert_equal "www.capistrano.test", server.host
|
50
|
+
assert_equal "jamis", server.user
|
51
|
+
assert_equal 8080, server.port
|
52
|
+
assert server.options.empty?
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_new_with_option_should_dup_option_hash
|
56
|
+
options = {}
|
57
|
+
server = Capistrano::ServerDefinition.new("www.capistrano.test", options)
|
58
|
+
assert_not_equal options.object_id, server.options.object_id
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_new_with_options_should_keep_options
|
62
|
+
server = Capistrano::ServerDefinition.new("www.capistrano.test", :primary => true)
|
63
|
+
assert_equal true, server.options[:primary]
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_default_user_should_try_to_guess_username
|
67
|
+
ENV.stubs(:[]).returns(nil)
|
68
|
+
assert_equal "not-specified", Capistrano::ServerDefinition.default_user
|
69
|
+
|
70
|
+
ENV.stubs(:[]).returns(nil)
|
71
|
+
ENV.stubs(:[]).with("USERNAME").returns("ryan")
|
72
|
+
assert_equal "ryan", Capistrano::ServerDefinition.default_user
|
73
|
+
|
74
|
+
ENV.stubs(:[]).returns(nil)
|
75
|
+
ENV.stubs(:[]).with("USER").returns("jamis")
|
76
|
+
assert_equal "jamis", Capistrano::ServerDefinition.default_user
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_comparison_should_match_when_host_user_port_are_same
|
80
|
+
s1 = server("jamis@www.capistrano.test:8080")
|
81
|
+
s2 = server("www.capistrano.test", :user => "jamis", :port => 8080)
|
82
|
+
assert_equal s1, s2
|
83
|
+
assert_equal s1.hash, s2.hash
|
84
|
+
assert s1.eql?(s2)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_servers_should_be_comparable
|
88
|
+
s1 = server("jamis@www.capistrano.test:8080")
|
89
|
+
s2 = server("www.alphabet.test:1234")
|
90
|
+
s3 = server("jamis@www.capistrano.test:8075")
|
91
|
+
s4 = server("billy@www.capistrano.test:8080")
|
92
|
+
|
93
|
+
assert s2 < s1
|
94
|
+
assert s3 < s1
|
95
|
+
assert s4 < s1
|
96
|
+
assert s2 < s3
|
97
|
+
assert s2 < s4
|
98
|
+
assert s3 < s4
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_comparison_should_not_match_when_any_of_host_user_port_differ
|
102
|
+
s1 = server("jamis@www.capistrano.test:8080")
|
103
|
+
s2 = server("bob@www.capistrano.test:8080")
|
104
|
+
s3 = server("jamis@www.capistrano.test:8081")
|
105
|
+
s4 = server("jamis@app.capistrano.test:8080")
|
106
|
+
assert_not_equal s1, s2
|
107
|
+
assert_not_equal s1, s3
|
108
|
+
assert_not_equal s1, s4
|
109
|
+
assert_not_equal s2, s3
|
110
|
+
assert_not_equal s2, s4
|
111
|
+
assert_not_equal s3, s4
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_to_s
|
115
|
+
assert_equal "www.capistrano.test", server("www.capistrano.test").to_s
|
116
|
+
assert_equal "www.capistrano.test", server("www.capistrano.test:22").to_s
|
117
|
+
assert_equal "www.capistrano.test:1234", server("www.capistrano.test:1234").to_s
|
118
|
+
assert_equal "jamis@www.capistrano.test", server("jamis@www.capistrano.test").to_s
|
119
|
+
assert_equal "jamis@www.capistrano.test:1234", server("jamis@www.capistrano.test:1234").to_s
|
120
|
+
end
|
121
|
+
end
|
data/test/shell_test.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/configuration'
|
3
|
+
require 'capistrano/shell'
|
4
|
+
|
5
|
+
class ShellTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@config = Capistrano::Configuration.new
|
8
|
+
@shell = Capistrano::Shell.new(@config)
|
9
|
+
@shell.stubs(:puts)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_readline_fallback_prompt_should_write_to_stdout_and_read_from_stdin
|
13
|
+
STDOUT.expects(:print).with("prompt> ")
|
14
|
+
STDOUT.expects(:flush)
|
15
|
+
STDIN.expects(:gets).returns("hi\n")
|
16
|
+
assert_equal "hi\n", Capistrano::Shell::ReadlineFallback.readline("prompt> ")
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_question_mark_as_input_should_trigger_help
|
20
|
+
@shell.expects(:read_line).returns("?")
|
21
|
+
@shell.expects(:help)
|
22
|
+
assert @shell.read_and_execute
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_help_as_input_should_trigger_help
|
26
|
+
@shell.expects(:read_line).returns("help")
|
27
|
+
@shell.expects(:help)
|
28
|
+
assert @shell.read_and_execute
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_quit_as_input_should_cause_read_and_execute_to_return_false
|
32
|
+
@shell.expects(:read_line).returns("quit")
|
33
|
+
assert !@shell.read_and_execute
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_exit_as_input_should_cause_read_and_execute_to_return_false
|
37
|
+
@shell.expects(:read_line).returns("exit")
|
38
|
+
assert !@shell.read_and_execute
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_set_should_parse_flag_and_value_and_call_set_option
|
42
|
+
@shell.expects(:read_line).returns("set -v 5")
|
43
|
+
@shell.expects(:set_option).with("v", "5")
|
44
|
+
assert @shell.read_and_execute
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_set_with_colon_changes_setting
|
48
|
+
@shell.expects(:read_line).returns("set :random_setting value")
|
49
|
+
@shell.configuration.expects(:set).with(:random_setting, "value")
|
50
|
+
assert @shell.read_and_execute
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_text_without_with_or_on_gets_processed_verbatim
|
54
|
+
@shell.expects(:read_line).returns("hello world")
|
55
|
+
@shell.expects(:process_command).with(nil, nil, "hello world")
|
56
|
+
assert @shell.read_and_execute
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_text_with_with_gets_processed_with_with # lol
|
60
|
+
@shell.expects(:read_line).returns("with app,db hello world")
|
61
|
+
@shell.expects(:process_command).with("with", "app,db", "hello world")
|
62
|
+
assert @shell.read_and_execute
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_text_with_on_gets_processed_with_on
|
66
|
+
@shell.expects(:read_line).returns("on app,db hello world")
|
67
|
+
@shell.expects(:process_command).with("on", "app,db", "hello world")
|
68
|
+
assert @shell.read_and_execute
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_task_command_with_bang_gets_processed_by_exec_tasks
|
72
|
+
while_testing_post_exec_commands do
|
73
|
+
@shell.expects(:read_line).returns("!deploy")
|
74
|
+
@shell.expects(:exec_tasks).with(["deploy"])
|
75
|
+
assert @shell.read_and_execute
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_normal_command_gets_processed_by_exec_command
|
80
|
+
while_testing_post_exec_commands do
|
81
|
+
@shell.expects(:read_line).returns("uptime")
|
82
|
+
@shell.expects(:exec_command).with("uptime",nil)
|
83
|
+
@shell.expects(:connect)
|
84
|
+
assert @shell.read_and_execute
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def while_testing_post_exec_commands(&block)
|
92
|
+
@shell.instance_variable_set(:@mutex,Mutex.new)
|
93
|
+
yield
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
data/test/ssh_test.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/ssh'
|
3
|
+
|
4
|
+
class SSHTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Capistrano::ServerDefinition.stubs(:default_user).returns("default-user")
|
7
|
+
@options = { :password => nil,
|
8
|
+
:auth_methods => %w(publickey hostbased),
|
9
|
+
:config => false }
|
10
|
+
@server = server("capistrano")
|
11
|
+
Net::SSH.stubs(:configuration_for).returns({})
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_connect_with_bare_server_without_options_or_config_with_public_key_succeeding_should_only_loop_once
|
15
|
+
Net::SSH.expects(:start).with(@server.host, "default-user", @options).returns(success = Object.new)
|
16
|
+
assert_equal success, Capistrano::SSH.connect(@server)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_connect_with_bare_server_without_options_with_public_key_failing_should_try_password
|
20
|
+
Net::SSH.expects(:start).with(@server.host, "default-user", @options).raises(Net::SSH::AuthenticationFailed)
|
21
|
+
Net::SSH.expects(:start).with(@server.host, "default-user", @options.merge(:password => "f4b13n", :auth_methods => %w(password keyboard-interactive))).returns(success = Object.new)
|
22
|
+
assert_equal success, Capistrano::SSH.connect(@server, :password => "f4b13n")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_connect_with_bare_server_without_options_public_key_and_password_failing_should_raise_error
|
26
|
+
Net::SSH.expects(:start).with(@server.host, "default-user", @options).raises(Net::SSH::AuthenticationFailed)
|
27
|
+
Net::SSH.expects(:start).with(@server.host, "default-user", @options.merge(:password => "f4b13n", :auth_methods => %w(password keyboard-interactive))).raises(Net::SSH::AuthenticationFailed)
|
28
|
+
assert_raises(Net::SSH::AuthenticationFailed) do
|
29
|
+
Capistrano::SSH.connect(@server, :password => "f4b13n")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_connect_with_bare_server_and_user_via_public_key_should_pass_user_to_net_ssh
|
34
|
+
Net::SSH.expects(:start).with(@server.host, "jamis", @options).returns(success = Object.new)
|
35
|
+
assert_equal success, Capistrano::SSH.connect(@server, :user => "jamis")
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_connect_with_bare_server_and_user_via_password_should_pass_user_to_net_ssh
|
39
|
+
Net::SSH.expects(:start).with(@server.host, "jamis", @options).raises(Net::SSH::AuthenticationFailed)
|
40
|
+
Net::SSH.expects(:start).with(@server.host, "jamis", @options.merge(:password => "f4b13n", :auth_methods => %w(password keyboard-interactive))).returns(success = Object.new)
|
41
|
+
assert_equal success, Capistrano::SSH.connect(@server, :user => "jamis", :password => "f4b13n")
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_connect_with_bare_server_with_explicit_port_should_pass_port_to_net_ssh
|
45
|
+
Net::SSH.expects(:start).with(@server.host, "default-user", @options.merge(:port => 1234)).returns(success = Object.new)
|
46
|
+
assert_equal success, Capistrano::SSH.connect(@server, :port => 1234)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_connect_with_server_with_user_should_pass_user_to_net_ssh
|
50
|
+
server = server("jamis@capistrano")
|
51
|
+
Net::SSH.expects(:start).with(server.host, "jamis", @options).returns(success = Object.new)
|
52
|
+
assert_equal success, Capistrano::SSH.connect(server)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_connect_with_server_with_port_should_pass_port_to_net_ssh
|
56
|
+
server = server("capistrano:1235")
|
57
|
+
Net::SSH.expects(:start).with(server.host, "default-user", @options.merge(:port => 1235)).returns(success = Object.new)
|
58
|
+
assert_equal success, Capistrano::SSH.connect(server)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_connect_with_server_with_user_and_port_should_pass_user_and_port_to_net_ssh
|
62
|
+
server = server("jamis@capistrano:1235")
|
63
|
+
Net::SSH.expects(:start).with(server.host, "jamis", @options.merge(:port => 1235)).returns(success = Object.new)
|
64
|
+
assert_equal success, Capistrano::SSH.connect(server)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_connect_with_server_with_other_ssh_options_should_pass_ssh_options_to_net_ssh
|
68
|
+
server = server("jamis@capistrano:1235", :ssh_options => { :keys => %w(some_valid_key), :auth_methods => %w(a_method), :hmac => 'none' })
|
69
|
+
Net::SSH.expects(:start).with(server.host, "jamis", @options.merge(:port => 1235, :keys => %w(some_valid_key), :auth_methods => %w(a_method), :hmac => 'none' )).returns(success = Object.new)
|
70
|
+
assert_equal success, Capistrano::SSH.connect(server)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_connect_with_ssh_options_should_use_ssh_options
|
74
|
+
ssh_options = { :username => "JamisMan", :port => 8125, :config => false }
|
75
|
+
Net::SSH.expects(:start).with(@server.host, "JamisMan", @options.merge(:port => 8125, :config => false)).returns(success = Object.new)
|
76
|
+
assert_equal success, Capistrano::SSH.connect(@server, {:ssh_options => ssh_options})
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_connect_with_options_and_ssh_options_should_see_options_override_ssh_options
|
80
|
+
ssh_options = { :username => "JamisMan", :port => 8125, :forward_agent => true }
|
81
|
+
Net::SSH.expects(:start).with(@server.host, "jamis", @options.merge(:port => 1235, :forward_agent => true)).returns(success = Object.new)
|
82
|
+
assert_equal success, Capistrano::SSH.connect(@server, :ssh_options => ssh_options, :user => "jamis", :port => 1235)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_connect_with_verbose_option_should_set_verbose_option_on_ssh
|
86
|
+
Net::SSH.expects(:start).with(@server.host, "default-user", @options).returns(success = Object.new)
|
87
|
+
assert_equal success, Capistrano::SSH.connect(@server, :verbose => 0)
|
88
|
+
Net::SSH.expects(:start).with(@server.host, "default-user", @options.merge(:verbose => :debug)).returns(success = Object.new)
|
89
|
+
assert_equal success, Capistrano::SSH.connect(@server, :verbose => 1)
|
90
|
+
Net::SSH.expects(:start).with(@server.host, "default-user", @options.merge(:verbose => :debug)).returns(success = Object.new)
|
91
|
+
assert_equal success, Capistrano::SSH.connect(@server, :verbose => 2)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_connect_with_ssh_options_should_see_server_options_override_ssh_options
|
95
|
+
ssh_options = { :username => "JamisMan", :port => 8125, :forward_agent => true }
|
96
|
+
server = server("jamis@capistrano:1235")
|
97
|
+
Net::SSH.expects(:start).with(server.host, "jamis", @options.merge(:port => 1235, :forward_agent => true, :config => false)).returns(success = Object.new)
|
98
|
+
assert_equal success, Capistrano::SSH.connect(server, {:ssh_options => ssh_options})
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_connect_should_add_xserver_accessor_to_connection
|
102
|
+
Net::SSH.expects(:start).with(@server.host, "default-user", @options).returns(success = Object.new)
|
103
|
+
assert_equal success, Capistrano::SSH.connect(@server)
|
104
|
+
assert success.respond_to?(:xserver)
|
105
|
+
assert success.respond_to?(:xserver)
|
106
|
+
assert_equal success.xserver, @server
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_connect_should_not_retry_if_custom_auth_methods_are_given
|
110
|
+
Net::SSH.expects(:start).with(@server.host, "default-user", @options.merge(:auth_methods => %w(publickey))).raises(Net::SSH::AuthenticationFailed)
|
111
|
+
assert_raises(Net::SSH::AuthenticationFailed) { Capistrano::SSH.connect(@server, :ssh_options => { :auth_methods => %w(publickey) }) }
|
112
|
+
end
|
113
|
+
end
|