capistrano 1.4.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +140 -4
- data/MIT-LICENSE +1 -1
- data/README +22 -14
- data/bin/cap +1 -8
- data/bin/capify +77 -0
- data/examples/sample.rb +10 -109
- data/lib/capistrano.rb +1 -0
- data/lib/capistrano/callback.rb +41 -0
- data/lib/capistrano/cli.rb +17 -317
- data/lib/capistrano/cli/execute.rb +82 -0
- data/lib/capistrano/cli/help.rb +102 -0
- data/lib/capistrano/cli/help.txt +53 -0
- data/lib/capistrano/cli/options.rb +183 -0
- data/lib/capistrano/cli/ui.rb +28 -0
- data/lib/capistrano/command.rb +62 -29
- data/lib/capistrano/configuration.rb +25 -226
- data/lib/capistrano/configuration/actions/file_transfer.rb +35 -0
- data/lib/capistrano/configuration/actions/inspect.rb +46 -0
- data/lib/capistrano/configuration/actions/invocation.rb +127 -0
- data/lib/capistrano/configuration/callbacks.rb +148 -0
- data/lib/capistrano/configuration/connections.rb +159 -0
- data/lib/capistrano/configuration/execution.rb +126 -0
- data/lib/capistrano/configuration/loading.rb +112 -0
- data/lib/capistrano/configuration/namespaces.rb +190 -0
- data/lib/capistrano/configuration/roles.rb +51 -0
- data/lib/capistrano/configuration/servers.rb +75 -0
- data/lib/capistrano/configuration/variables.rb +127 -0
- data/lib/capistrano/errors.rb +15 -0
- data/lib/capistrano/extensions.rb +27 -8
- data/lib/capistrano/gateway.rb +54 -29
- data/lib/capistrano/logger.rb +11 -11
- data/lib/capistrano/recipes/compat.rb +32 -0
- data/lib/capistrano/recipes/deploy.rb +483 -0
- data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
- data/lib/capistrano/recipes/deploy/local_dependency.rb +46 -0
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +65 -0
- data/lib/capistrano/recipes/deploy/scm.rb +19 -0
- data/lib/capistrano/recipes/deploy/scm/base.rb +180 -0
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +151 -0
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +85 -0
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +129 -0
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +126 -0
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +103 -0
- data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
- data/lib/capistrano/recipes/deploy/strategy/base.rb +64 -0
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +143 -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 +47 -0
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/recipes/standard.rb +26 -276
- data/lib/capistrano/recipes/templates/maintenance.rhtml +1 -1
- data/lib/capistrano/recipes/upgrade.rb +33 -0
- data/lib/capistrano/server_definition.rb +51 -0
- data/lib/capistrano/shell.rb +125 -81
- data/lib/capistrano/ssh.rb +80 -36
- data/lib/capistrano/task_definition.rb +69 -0
- data/lib/capistrano/upload.rb +146 -0
- data/lib/capistrano/version.rb +13 -17
- data/test/cli/execute_test.rb +132 -0
- data/test/cli/help_test.rb +139 -0
- data/test/cli/options_test.rb +226 -0
- data/test/cli/ui_test.rb +28 -0
- data/test/cli_test.rb +17 -0
- data/test/command_test.rb +284 -25
- data/test/configuration/actions/file_transfer_test.rb +40 -0
- data/test/configuration/actions/inspect_test.rb +62 -0
- data/test/configuration/actions/invocation_test.rb +195 -0
- data/test/configuration/callbacks_test.rb +206 -0
- data/test/configuration/connections_test.rb +288 -0
- data/test/configuration/execution_test.rb +159 -0
- data/test/configuration/loading_test.rb +119 -0
- data/test/configuration/namespace_dsl_test.rb +283 -0
- data/test/configuration/roles_test.rb +47 -0
- data/test/configuration/servers_test.rb +90 -0
- data/test/configuration/variables_test.rb +180 -0
- data/test/configuration_test.rb +60 -212
- data/test/deploy/scm/base_test.rb +55 -0
- data/test/deploy/strategy/copy_test.rb +146 -0
- data/test/extensions_test.rb +69 -0
- data/test/fixtures/cli_integration.rb +5 -0
- data/test/fixtures/custom.rb +2 -2
- data/test/gateway_test.rb +167 -0
- data/test/logger_test.rb +123 -0
- data/test/server_definition_test.rb +108 -0
- data/test/shell_test.rb +64 -0
- data/test/ssh_test.rb +67 -154
- data/test/task_definition_test.rb +101 -0
- data/test/upload_test.rb +131 -0
- data/test/utils.rb +31 -39
- data/test/version_test.rb +24 -0
- metadata +145 -98
- data/THANKS +0 -4
- data/lib/capistrano/actor.rb +0 -567
- data/lib/capistrano/generators/rails/deployment/deployment_generator.rb +0 -25
- data/lib/capistrano/generators/rails/deployment/templates/capistrano.rake +0 -49
- data/lib/capistrano/generators/rails/deployment/templates/deploy.rb +0 -122
- data/lib/capistrano/generators/rails/loader.rb +0 -20
- data/lib/capistrano/scm/base.rb +0 -61
- data/lib/capistrano/scm/baz.rb +0 -118
- data/lib/capistrano/scm/bzr.rb +0 -70
- data/lib/capistrano/scm/cvs.rb +0 -129
- data/lib/capistrano/scm/darcs.rb +0 -27
- data/lib/capistrano/scm/mercurial.rb +0 -83
- data/lib/capistrano/scm/perforce.rb +0 -139
- data/lib/capistrano/scm/subversion.rb +0 -128
- data/lib/capistrano/transfer.rb +0 -97
- data/lib/capistrano/utils.rb +0 -26
- data/test/actor_test.rb +0 -402
- data/test/scm/cvs_test.rb +0 -196
- data/test/scm/subversion_test.rb +0 -145
@@ -0,0 +1,69 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/utils"
|
2
|
+
require 'capistrano'
|
3
|
+
|
4
|
+
class ExtensionsTest < Test::Unit::TestCase
|
5
|
+
module CustomExtension
|
6
|
+
def do_something(command)
|
7
|
+
run(command)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@config = Capistrano::Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
Capistrano::EXTENSIONS.keys.each { |e| Capistrano.remove_plugin(e) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_register_plugin_should_add_instance_method_on_configuration_and_return_true
|
20
|
+
assert !@config.respond_to?(:custom_stuff)
|
21
|
+
assert Capistrano.plugin(:custom_stuff, CustomExtension)
|
22
|
+
assert @config.respond_to?(:custom_stuff)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_register_plugin_that_already_exists_should_return_false
|
26
|
+
assert Capistrano.plugin(:custom_stuff, CustomExtension)
|
27
|
+
assert !Capistrano.plugin(:custom_stuff, CustomExtension)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_register_plugin_with_public_method_name_should_fail
|
31
|
+
method = Capistrano::Configuration.public_instance_methods.first
|
32
|
+
assert_not_nil method, "need a public instance method for testing"
|
33
|
+
assert_raises(Capistrano::Error) { Capistrano.plugin(method, CustomExtension) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_register_plugin_with_protected_method_name_should_fail
|
37
|
+
method = Capistrano::Configuration.protected_instance_methods.first
|
38
|
+
assert_not_nil method, "need a protected instance method for testing"
|
39
|
+
assert_raises(Capistrano::Error) { Capistrano.plugin(method, CustomExtension) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_register_plugin_with_private_method_name_should_fail
|
43
|
+
method = Capistrano::Configuration.private_instance_methods.first
|
44
|
+
assert_not_nil method, "need a private instance method for testing"
|
45
|
+
assert_raises(Capistrano::Error) { Capistrano.plugin(method, CustomExtension) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_unregister_plugin_that_does_not_exist_should_return_false
|
49
|
+
assert !Capistrano.remove_plugin(:custom_stuff)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_unregister_plugin_should_remove_method_and_return_true
|
53
|
+
assert Capistrano.plugin(:custom_stuff, CustomExtension)
|
54
|
+
assert @config.respond_to?(:custom_stuff)
|
55
|
+
assert Capistrano.remove_plugin(:custom_stuff)
|
56
|
+
assert !@config.respond_to?(:custom_stuff)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_registered_plugin_proxy_should_return_proxy_object
|
60
|
+
Capistrano.plugin(:custom_stuff, CustomExtension)
|
61
|
+
assert_instance_of Capistrano::ExtensionProxy, @config.custom_stuff
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_proxy_object_should_delegate_to_configuration
|
65
|
+
Capistrano.plugin(:custom_stuff, CustomExtension)
|
66
|
+
@config.expects(:run).with("hello")
|
67
|
+
@config.custom_stuff.do_something("hello")
|
68
|
+
end
|
69
|
+
end
|
data/test/fixtures/custom.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
ConfigurationLoadingTest::MockConfig.instance(:must_exist).load do
|
2
|
+
ping! :custom
|
3
3
|
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/utils"
|
2
|
+
require 'capistrano/gateway'
|
3
|
+
|
4
|
+
class GatewayTest < Test::Unit::TestCase
|
5
|
+
def teardown
|
6
|
+
Thread.list { |t| t.kill unless Thread.current == t }
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_initialize_should_open_and_set_session_value
|
10
|
+
run_test_initialize_should_open_and_set_session_value
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initialize_when_connect_lags_should_open_and_set_session_value
|
14
|
+
run_test_initialize_should_open_and_set_session_value do |expects|
|
15
|
+
expects.with { |*args| sleep 0.2; true }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_shutdown_without_any_open_connections_should_terminate_session
|
20
|
+
gateway = new_gateway
|
21
|
+
gateway.shutdown!
|
22
|
+
assert !gateway.thread.alive?
|
23
|
+
assert !gateway.session.looping?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_connect_to_should_start_local_ports_at_65535
|
27
|
+
gateway = new_gateway
|
28
|
+
expect_connect_to(:host => "127.0.0.1", :port => 65535).returns(result = sess_with_xserver("app1"))
|
29
|
+
newsess = gateway.connect_to(server("app1"))
|
30
|
+
assert_equal result, newsess
|
31
|
+
assert_equal [65535, "app1", 22], gateway.session.forward.active_locals[65535]
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_connect_to_should_decrement_port_and_retry_if_ports_are_in_use
|
35
|
+
gateway = new_gateway(:reserved => lambda { |n| n > 65000 })
|
36
|
+
expect_connect_to(:host => "127.0.0.1", :port => 65000).returns(result = sess_with_xserver("app1"))
|
37
|
+
newsess = gateway.connect_to(server("app1"))
|
38
|
+
assert_equal result, newsess
|
39
|
+
assert_equal [65000, "app1", 22], gateway.session.forward.active_locals[65000]
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_connect_to_should_honor_user_specification_in_server_definition
|
43
|
+
gateway = new_gateway
|
44
|
+
expect_connect_to(:host => "127.0.0.1", :user => "jamis", :port => 65535).returns(result = sess_with_xserver("app1"))
|
45
|
+
newsess = gateway.connect_to(server("jamis@app1"))
|
46
|
+
assert_equal result, newsess
|
47
|
+
assert_equal [65535, "app1", 22], gateway.session.forward.active_locals[65535]
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_connect_to_should_honor_port_specification_in_server_definition
|
51
|
+
gateway = new_gateway
|
52
|
+
expect_connect_to(:host => "127.0.0.1", :port => 65535).returns(result = sess_with_xserver("app1"))
|
53
|
+
newsess = gateway.connect_to(server("app1:1234"))
|
54
|
+
assert_equal result, newsess
|
55
|
+
assert_equal [65535, "app1", 1234], gateway.session.forward.active_locals[65535]
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_connect_to_should_set_xserver_to_tunnel_target
|
59
|
+
gateway = new_gateway
|
60
|
+
expect_connect_to(:host => "127.0.0.1", :port => 65535).returns(result = sess_with_xserver("app1"))
|
61
|
+
newsess = gateway.connect_to(server("app1:1234"))
|
62
|
+
assert_equal result, newsess
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_shutdown_should_cancel_active_forwarded_ports
|
66
|
+
gateway = new_gateway
|
67
|
+
expect_connect_to(:host => "127.0.0.1", :port => 65535).returns(sess_with_xserver("app1"))
|
68
|
+
gateway.connect_to(server("app1"))
|
69
|
+
assert !gateway.session.forward.active_locals.empty?
|
70
|
+
gateway.shutdown!
|
71
|
+
assert gateway.session.forward.active_locals.empty?
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_error_while_connecting_should_cause_connection_to_fail
|
75
|
+
gateway = new_gateway
|
76
|
+
expect_connect_to(:host => "127.0.0.1").raises(RuntimeError)
|
77
|
+
gateway.expects(:warn).times(2)
|
78
|
+
assert_raises(Capistrano::ConnectionError) { gateway.connect_to(server("app1")) }
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_connection_error_should_include_accessor_with_host_array
|
82
|
+
gateway = new_gateway
|
83
|
+
expect_connect_to(:host => "127.0.0.1").raises(RuntimeError)
|
84
|
+
gateway.expects(:warn).times(2)
|
85
|
+
|
86
|
+
begin
|
87
|
+
gateway.connect_to(server("app1"))
|
88
|
+
flunk "expected an exception to be raised"
|
89
|
+
rescue Capistrano::ConnectionError => e
|
90
|
+
assert e.respond_to?(:hosts)
|
91
|
+
assert_equal %w(app1), e.hosts.map { |h| h.to_s }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def sess_with_xserver(host)
|
98
|
+
s = server(host)
|
99
|
+
sess = mock("session")
|
100
|
+
sess.expects(:xserver=).with { |v| v.host == host }
|
101
|
+
sess
|
102
|
+
end
|
103
|
+
|
104
|
+
def expect_connect_to(options={})
|
105
|
+
Capistrano::SSH.expects(:connect).with do |server,config|
|
106
|
+
options.all? do |key, value|
|
107
|
+
case key
|
108
|
+
when :host then server.host == value
|
109
|
+
when :user then server.user == value
|
110
|
+
when :port then server.port == value
|
111
|
+
else false
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def new_gateway(options={})
|
118
|
+
expect_connect_to(:host => "capistrano").yields(MockSession.new(options))
|
119
|
+
Capistrano::Gateway.new(server("capistrano"))
|
120
|
+
end
|
121
|
+
|
122
|
+
def run_test_initialize_should_open_and_set_session_value
|
123
|
+
session = mock("Net::SSH session")
|
124
|
+
session.expects(:loop)
|
125
|
+
expectation = Capistrano::SSH.expects(:connect).yields(session)
|
126
|
+
yield expectation if block_given?
|
127
|
+
gateway = Capistrano::Gateway.new(server("capistrano"))
|
128
|
+
gateway.thread.join
|
129
|
+
assert_equal session, gateway.session
|
130
|
+
end
|
131
|
+
|
132
|
+
class MockForward
|
133
|
+
attr_reader :active_locals
|
134
|
+
|
135
|
+
def initialize(options)
|
136
|
+
@options = options
|
137
|
+
@active_locals = {}
|
138
|
+
end
|
139
|
+
|
140
|
+
def cancel_local(port)
|
141
|
+
@active_locals.delete(port)
|
142
|
+
end
|
143
|
+
|
144
|
+
def local(lport, host, rport)
|
145
|
+
raise Errno::EADDRINUSE if @options[:reserved] && @options[:reserved][lport]
|
146
|
+
@active_locals[lport] = [lport, host, rport]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
class MockSession
|
151
|
+
attr_reader :forward
|
152
|
+
|
153
|
+
def initialize(options={})
|
154
|
+
@forward = MockForward.new(options)
|
155
|
+
end
|
156
|
+
|
157
|
+
def looping?
|
158
|
+
@looping
|
159
|
+
end
|
160
|
+
|
161
|
+
def loop
|
162
|
+
@looping = true
|
163
|
+
sleep 0.1 while yield
|
164
|
+
@looping = false
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
data/test/logger_test.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/utils"
|
2
|
+
require 'capistrano/logger'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
class LoggerTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@io = StringIO.new
|
8
|
+
@logger = Capistrano::Logger.new(:output => @io)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_logger_should_use_STDERR_by_default
|
12
|
+
logger = Capistrano::Logger.new
|
13
|
+
assert_equal STDERR, logger.device
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_logger_should_use_output_option_if_output_responds_to_puts
|
17
|
+
logger = Capistrano::Logger.new(:output => STDOUT)
|
18
|
+
assert_equal STDOUT, logger.device
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_logger_should_open_file_if_output_does_not_respond_to_puts
|
22
|
+
File.expects(:open).with("logs/capistrano.log", "a").returns(:mock)
|
23
|
+
logger = Capistrano::Logger.new(:output => "logs/capistrano.log")
|
24
|
+
assert_equal :mock, logger.device
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_close_should_not_close_device_if_device_is_default
|
28
|
+
logger = Capistrano::Logger.new
|
29
|
+
logger.device.expects(:close).never
|
30
|
+
logger.close
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_close_should_not_close_device_is_device_is_explicitly_given
|
34
|
+
logger = Capistrano::Logger.new(:output => STDOUT)
|
35
|
+
STDOUT.expects(:close).never
|
36
|
+
logger.close
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_close_should_close_device_when_device_was_implicitly_opened
|
40
|
+
f = mock("file", :close => nil)
|
41
|
+
File.expects(:open).with("logs/capistrano.log", "a").returns(f)
|
42
|
+
logger = Capistrano::Logger.new(:output => "logs/capistrano.log")
|
43
|
+
logger.close
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_log_with_level_greater_than_threshold_should_ignore_message
|
47
|
+
@logger.level = 3
|
48
|
+
@logger.log(4, "message")
|
49
|
+
assert @io.string.empty?
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_log_with_level_equal_to_threshold_should_log_message
|
53
|
+
@logger.level = 3
|
54
|
+
@logger.log(3, "message")
|
55
|
+
assert @io.string.include?("message")
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_log_with_level_less_than_threshold_should_log_message
|
59
|
+
@logger.level = 3
|
60
|
+
@logger.log(2, "message")
|
61
|
+
assert @io.string.include?("message")
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_log_with_multiline_message_should_log_each_line_separately
|
65
|
+
@logger.log(0, "first line\nsecond line")
|
66
|
+
assert @io.string.include?("*** first line")
|
67
|
+
assert @io.string.include?("*** second line")
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_log_with_line_prefix_should_insert_line_prefix_before_message
|
71
|
+
@logger.log(0, "message", "prefix")
|
72
|
+
assert @io.string.include?("*** [prefix] message")
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_log_with_level_0_should_have_strong_indent
|
76
|
+
@logger.log(0, "message")
|
77
|
+
assert @io.string.match(/^\*\*\* message/)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_log_with_level_1_should_have_weaker_indent
|
81
|
+
@logger.level = 1
|
82
|
+
@logger.log(1, "message")
|
83
|
+
assert @io.string.match(/^ \*\* message/)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_log_with_level_2_should_have_weaker_indent
|
87
|
+
@logger.level = 2
|
88
|
+
@logger.log(2, "message")
|
89
|
+
assert @io.string.match(/^ \* message/)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_log_with_level_3_should_have_weakest_indent
|
93
|
+
@logger.level = 3
|
94
|
+
@logger.log(3, "message")
|
95
|
+
assert @io.string.match(/^ message/)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_important_should_delegate_to_log_with_level_IMPORTANT
|
99
|
+
@logger.expects(:log).with(Capistrano::Logger::IMPORTANT, "message", "prefix")
|
100
|
+
@logger.important("message", "prefix")
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_info_should_delegate_to_log_with_level_INFO
|
104
|
+
@logger.expects(:log).with(Capistrano::Logger::INFO, "message", "prefix")
|
105
|
+
@logger.info("message", "prefix")
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_debug_should_delegate_to_log_with_level_DEBUG
|
109
|
+
@logger.expects(:log).with(Capistrano::Logger::DEBUG, "message", "prefix")
|
110
|
+
@logger.debug("message", "prefix")
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_trace_should_delegate_to_log_with_level_TRACE
|
114
|
+
@logger.expects(:log).with(Capistrano::Logger::TRACE, "message", "prefix")
|
115
|
+
@logger.trace("message", "prefix")
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_ordering_of_levels
|
119
|
+
assert Capistrano::Logger::IMPORTANT < Capistrano::Logger::INFO
|
120
|
+
assert Capistrano::Logger::INFO < Capistrano::Logger::DEBUG
|
121
|
+
assert Capistrano::Logger::DEBUG < Capistrano::Logger::TRACE
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/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_comparison_should_match_when_host_user_port_are_same
|
67
|
+
s1 = server("jamis@www.capistrano.test:8080")
|
68
|
+
s2 = server("www.capistrano.test", :user => "jamis", :port => 8080)
|
69
|
+
assert_equal s1, s2
|
70
|
+
assert_equal s1.hash, s2.hash
|
71
|
+
assert s1.eql?(s2)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_servers_should_be_comparable
|
75
|
+
s1 = server("jamis@www.capistrano.test:8080")
|
76
|
+
s2 = server("www.alphabet.test:1234")
|
77
|
+
s3 = server("jamis@www.capistrano.test:8075")
|
78
|
+
s4 = server("billy@www.capistrano.test:8080")
|
79
|
+
|
80
|
+
assert s2 < s1
|
81
|
+
assert s3 < s1
|
82
|
+
assert s4 < s1
|
83
|
+
assert s2 < s3
|
84
|
+
assert s2 < s4
|
85
|
+
assert s3 < s4
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_comparison_should_not_match_when_any_of_host_user_port_differ
|
89
|
+
s1 = server("jamis@www.capistrano.test:8080")
|
90
|
+
s2 = server("bob@www.capistrano.test:8080")
|
91
|
+
s3 = server("jamis@www.capistrano.test:8081")
|
92
|
+
s4 = server("jamis@app.capistrano.test:8080")
|
93
|
+
assert_not_equal s1, s2
|
94
|
+
assert_not_equal s1, s3
|
95
|
+
assert_not_equal s1, s4
|
96
|
+
assert_not_equal s2, s3
|
97
|
+
assert_not_equal s2, s4
|
98
|
+
assert_not_equal s3, s4
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_to_s
|
102
|
+
assert_equal "www.capistrano.test", server("www.capistrano.test").to_s
|
103
|
+
assert_equal "www.capistrano.test", server("www.capistrano.test:22").to_s
|
104
|
+
assert_equal "www.capistrano.test:1234", server("www.capistrano.test:1234").to_s
|
105
|
+
assert_equal "jamis@www.capistrano.test", server("jamis@www.capistrano.test").to_s
|
106
|
+
assert_equal "jamis@www.capistrano.test:1234", server("jamis@www.capistrano.test:1234").to_s
|
107
|
+
end
|
108
|
+
end
|