capistrano 2.0.0 → 2.15.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +7 -0
- data/CHANGELOG +737 -18
- data/Gemfile +13 -0
- data/README.md +94 -0
- data/Rakefile +11 -0
- data/bin/cap +0 -0
- data/bin/capify +37 -22
- data/capistrano.gemspec +40 -0
- data/lib/capistrano/callback.rb +5 -1
- data/lib/capistrano/cli/execute.rb +10 -7
- data/lib/capistrano/cli/help.rb +39 -16
- data/lib/capistrano/cli/help.txt +44 -16
- data/lib/capistrano/cli/options.rb +71 -11
- data/lib/capistrano/cli/ui.rb +13 -1
- data/lib/capistrano/cli.rb +5 -5
- data/lib/capistrano/command.rb +215 -58
- data/lib/capistrano/configuration/actions/file_transfer.rb +29 -14
- data/lib/capistrano/configuration/actions/inspect.rb +3 -3
- data/lib/capistrano/configuration/actions/invocation.rb +224 -22
- data/lib/capistrano/configuration/alias_task.rb +26 -0
- data/lib/capistrano/configuration/callbacks.rb +26 -27
- data/lib/capistrano/configuration/connections.rb +130 -52
- data/lib/capistrano/configuration/execution.rb +34 -18
- data/lib/capistrano/configuration/loading.rb +99 -6
- data/lib/capistrano/configuration/log_formatters.rb +75 -0
- data/lib/capistrano/configuration/namespaces.rb +45 -12
- data/lib/capistrano/configuration/roles.rb +28 -2
- data/lib/capistrano/configuration/servers.rb +51 -10
- data/lib/capistrano/configuration/variables.rb +3 -3
- data/lib/capistrano/configuration.rb +20 -4
- data/lib/capistrano/errors.rb +12 -8
- data/lib/capistrano/ext/multistage.rb +67 -0
- data/lib/capistrano/ext/string.rb +5 -0
- data/lib/capistrano/extensions.rb +1 -1
- data/lib/capistrano/fix_rake_deprecated_dsl.rb +8 -0
- data/lib/capistrano/logger.rb +112 -5
- data/lib/capistrano/processable.rb +55 -0
- data/lib/capistrano/recipes/compat.rb +2 -2
- data/lib/capistrano/recipes/deploy/assets.rb +201 -0
- data/lib/capistrano/recipes/deploy/dependencies.rb +2 -2
- data/lib/capistrano/recipes/deploy/local_dependency.rb +10 -2
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +54 -2
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
- data/lib/capistrano/recipes/deploy/scm/base.rb +31 -11
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +14 -14
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +11 -9
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +12 -1
- data/lib/capistrano/recipes/deploy/scm/git.rb +293 -0
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +23 -15
- data/lib/capistrano/recipes/deploy/scm/none.rb +55 -0
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +54 -28
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +36 -18
- data/lib/capistrano/recipes/deploy/scm.rb +1 -1
- data/lib/capistrano/recipes/deploy/strategy/base.rb +32 -4
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +238 -43
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +1 -1
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +11 -1
- data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +21 -0
- data/lib/capistrano/recipes/deploy/strategy.rb +1 -1
- data/lib/capistrano/recipes/deploy.rb +265 -123
- data/lib/capistrano/recipes/standard.rb +1 -1
- data/lib/capistrano/role.rb +102 -0
- data/lib/capistrano/server_definition.rb +6 -1
- data/lib/capistrano/shell.rb +30 -33
- data/lib/capistrano/ssh.rb +46 -60
- data/lib/capistrano/task_definition.rb +16 -8
- data/lib/capistrano/transfer.rb +218 -0
- data/lib/capistrano/version.rb +6 -17
- data/lib/capistrano.rb +4 -1
- data/test/cli/execute_test.rb +3 -3
- data/test/cli/help_test.rb +33 -7
- data/test/cli/options_test.rb +109 -6
- data/test/cli/ui_test.rb +2 -2
- data/test/cli_test.rb +3 -3
- data/test/command_test.rb +144 -124
- data/test/configuration/actions/file_transfer_test.rb +41 -20
- data/test/configuration/actions/inspect_test.rb +21 -7
- data/test/configuration/actions/invocation_test.rb +123 -30
- data/test/configuration/alias_task_test.rb +118 -0
- data/test/configuration/callbacks_test.rb +41 -46
- data/test/configuration/connections_test.rb +187 -36
- data/test/configuration/execution_test.rb +18 -2
- data/test/configuration/loading_test.rb +33 -4
- data/test/configuration/namespace_dsl_test.rb +54 -5
- data/test/configuration/roles_test.rb +114 -4
- data/test/configuration/servers_test.rb +97 -4
- data/test/configuration/variables_test.rb +12 -2
- data/test/configuration_test.rb +9 -13
- 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 +1 -1
- 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 +274 -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 +68 -0
- data/test/deploy/strategy/copy_test.rb +240 -26
- data/test/extensions_test.rb +2 -2
- data/test/logger_formatting_test.rb +149 -0
- data/test/logger_test.rb +13 -2
- data/test/recipes_test.rb +25 -0
- data/test/role_test.rb +11 -0
- data/test/server_definition_test.rb +15 -2
- data/test/shell_test.rb +33 -1
- data/test/ssh_test.rb +40 -24
- data/test/task_definition_test.rb +18 -2
- data/test/transfer_test.rb +168 -0
- data/test/utils.rb +28 -33
- metadata +215 -101
- data/MIT-LICENSE +0 -20
- data/README +0 -43
- data/examples/sample.rb +0 -14
- data/lib/capistrano/gateway.rb +0 -131
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +0 -53
- data/lib/capistrano/recipes/upgrade.rb +0 -33
- data/lib/capistrano/upload.rb +0 -146
- data/test/gateway_test.rb +0 -167
- data/test/upload_test.rb +0 -131
- data/test/version_test.rb +0 -24
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "utils"
|
|
2
2
|
require 'capistrano/configuration/roles'
|
|
3
|
+
require 'capistrano/server_definition'
|
|
3
4
|
|
|
4
5
|
class ConfigurationRolesTest < Test::Unit::TestCase
|
|
5
6
|
class MockConfig
|
|
@@ -21,21 +22,56 @@ class ConfigurationRolesTest < Test::Unit::TestCase
|
|
|
21
22
|
assert @config.roles.empty?
|
|
22
23
|
end
|
|
23
24
|
|
|
25
|
+
def test_roles_for_host_with_one_role
|
|
26
|
+
@config.role :app, "app1.capistrano.test"
|
|
27
|
+
@config.role :not_app, "not-app.capistrano.test"
|
|
28
|
+
app_server = @config.roles[:app].servers.first
|
|
29
|
+
assert @config.role_names_for_host(app_server)==[ :app ]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_roles_for_host_with_multiple_roles
|
|
33
|
+
@config.server "www.capistrano.test", :db, :worker
|
|
34
|
+
db_server = @config.roles[:db].servers.first
|
|
35
|
+
assert_equal @config.role_names_for_host(db_server).map(&:to_s).sort, [ 'db', 'worker' ]
|
|
36
|
+
end
|
|
37
|
+
|
|
24
38
|
def test_role_should_allow_empty_list
|
|
25
39
|
@config.role :app
|
|
40
|
+
assert @config.roles.keys.include?(:app)
|
|
26
41
|
assert @config.roles[:app].empty?
|
|
27
42
|
end
|
|
28
43
|
|
|
29
44
|
def test_role_with_one_argument_should_add_to_roles_collection
|
|
30
45
|
@config.role :app, "app1.capistrano.test"
|
|
31
46
|
assert_equal [:app], @config.roles.keys
|
|
32
|
-
|
|
47
|
+
assert_role_equals %w(app1.capistrano.test)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_role_block_returning_single_string_is_added_to_roles_collection
|
|
51
|
+
@config.role :app do
|
|
52
|
+
'app1.capistrano.test'
|
|
53
|
+
end
|
|
54
|
+
assert_role_equals %w(app1.capistrano.test)
|
|
33
55
|
end
|
|
34
56
|
|
|
35
57
|
def test_role_with_multiple_arguments_should_add_each_to_roles_collection
|
|
36
58
|
@config.role :app, "app1.capistrano.test", "app2.capistrano.test"
|
|
37
59
|
assert_equal [:app], @config.roles.keys
|
|
38
|
-
|
|
60
|
+
assert_role_equals %w(app1.capistrano.test app2.capistrano.test)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_role_with_block_and_strings_should_add_both_to_roles_collection
|
|
64
|
+
@config.role :app, 'app1.capistrano.test' do
|
|
65
|
+
'app2.capistrano.test'
|
|
66
|
+
end
|
|
67
|
+
assert_role_equals %w(app1.capistrano.test app2.capistrano.test)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_role_block_returning_array_should_add_each_to_roles_collection
|
|
71
|
+
@config.role :app do
|
|
72
|
+
['app1.capistrano.test', 'app2.capistrano.test']
|
|
73
|
+
end
|
|
74
|
+
assert_role_equals %w(app1.capistrano.test app2.capistrano.test)
|
|
39
75
|
end
|
|
40
76
|
|
|
41
77
|
def test_role_with_options_should_apply_options_to_each_argument
|
|
@@ -44,4 +80,78 @@ class ConfigurationRolesTest < Test::Unit::TestCase
|
|
|
44
80
|
assert_equal({:extra => :value}, server.options)
|
|
45
81
|
end
|
|
46
82
|
end
|
|
47
|
-
|
|
83
|
+
|
|
84
|
+
def test_role_with_options_should_apply_options_to_block_results
|
|
85
|
+
@config.role :app, :extra => :value do
|
|
86
|
+
['app1.capistrano.test', 'app2.capistrano.test']
|
|
87
|
+
end
|
|
88
|
+
@config.roles[:app].each do |server|
|
|
89
|
+
assert_equal({:extra => :value}, server.options)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_options_should_apply_only_to_this_argument_set
|
|
94
|
+
@config.role :app, 'app1.capistrano.test', 'app2.capistrano.test' do
|
|
95
|
+
['app3.capistrano.test', 'app4.capistrano.test']
|
|
96
|
+
end
|
|
97
|
+
@config.role :app, 'app5.capistrano.test', 'app6.capistrano.test', :extra => :value do
|
|
98
|
+
['app7.capistrano.test', 'app8.capistrano.test']
|
|
99
|
+
end
|
|
100
|
+
@config.role :app, 'app9.capistrano.test'
|
|
101
|
+
|
|
102
|
+
option_hosts = ['app5.capistrano.test', 'app6.capistrano.test', 'app7.capistrano.test', 'app8.capistrano.test']
|
|
103
|
+
@config.roles[:app].each do |server|
|
|
104
|
+
if (option_hosts.include? server.host)
|
|
105
|
+
assert_equal({:extra => :value}, server.options)
|
|
106
|
+
else
|
|
107
|
+
assert_not_equal({:extra => :value}, server.options)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Here, the source should be more readable than the method name
|
|
113
|
+
def test_role_block_returns_options_hash_is_merged_with_role_options_argument
|
|
114
|
+
@config.role :app, :first => :one, :second => :two do
|
|
115
|
+
['app1.capistrano.test', 'app2.capistrano.test', {:second => :please, :third => :three}]
|
|
116
|
+
end
|
|
117
|
+
@config.roles[:app].each do |server|
|
|
118
|
+
assert_equal({:first => :one, :second => :please, :third => :three}, server.options)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def test_role_block_can_override_role_options_argument
|
|
123
|
+
@config.role :app, :value => :wrong do
|
|
124
|
+
Capistrano::ServerDefinition.new('app.capistrano.test')
|
|
125
|
+
end
|
|
126
|
+
@config.roles[:app].servers
|
|
127
|
+
@config.roles[:app].servers.each do |server|
|
|
128
|
+
assert_not_equal({:value => :wrong}, server.options)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def test_role_block_can_return_nil
|
|
133
|
+
@config.role :app do
|
|
134
|
+
nil
|
|
135
|
+
end
|
|
136
|
+
assert_role_equals ([])
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def test_role_block_can_return_empty_array
|
|
140
|
+
@config.role :app do
|
|
141
|
+
[]
|
|
142
|
+
end
|
|
143
|
+
assert_role_equals ([])
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def test_role_definitions_via_server_should_associate_server_with_roles
|
|
147
|
+
@config.server "www.capistrano.test", :web, :app
|
|
148
|
+
assert_equal %w(www.capistrano.test), @config.roles[:app].map { |s| s.host }
|
|
149
|
+
assert_equal %w(www.capistrano.test), @config.roles[:web].map { |s| s.host }
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
private
|
|
153
|
+
|
|
154
|
+
def assert_role_equals(list)
|
|
155
|
+
assert_equal list, @config.roles[:app].map { |s| s.host }
|
|
156
|
+
end
|
|
157
|
+
end
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "utils"
|
|
2
2
|
require 'capistrano/task_definition'
|
|
3
3
|
require 'capistrano/configuration/servers'
|
|
4
4
|
|
|
5
5
|
class ConfigurationServersTest < Test::Unit::TestCase
|
|
6
6
|
class MockConfig
|
|
7
7
|
attr_reader :roles
|
|
8
|
+
attr_accessor :preserve_roles
|
|
8
9
|
|
|
9
10
|
def initialize
|
|
10
11
|
@roles = {}
|
|
12
|
+
@preserve_roles = false
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
include Capistrano::Configuration::Servers
|
|
@@ -37,6 +39,13 @@ class ConfigurationServersTest < Test::Unit::TestCase
|
|
|
37
39
|
assert_equal %w(web1 web2).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
|
38
40
|
end
|
|
39
41
|
|
|
42
|
+
# NOTE Rather than throw an error, as it used to, we return an
|
|
43
|
+
# empty array so that if a task is okay with a missing role it can continue on
|
|
44
|
+
def test_task_with_unknown_role_should_return_empty_array
|
|
45
|
+
task = new_task(:testing, @config, :roles => :bogus)
|
|
46
|
+
assert_equal [], @config.find_servers_for_task(task)
|
|
47
|
+
end
|
|
48
|
+
|
|
40
49
|
def test_task_with_hosts_option_should_apply_only_to_those_hosts
|
|
41
50
|
task = new_task(:testing, @config, :hosts => %w(foo bar))
|
|
42
51
|
assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
|
@@ -52,15 +61,82 @@ class ConfigurationServersTest < Test::Unit::TestCase
|
|
|
52
61
|
task = new_task(:testing)
|
|
53
62
|
assert_equal %w(app1 app2 app3 file).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
|
54
63
|
ensure
|
|
55
|
-
ENV
|
|
64
|
+
ENV.delete('ROLES')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_task_with_roles_as_environment_variable_and_preserve_roles_should_apply_only_to_existant_task_role
|
|
68
|
+
ENV['ROLES'] = "app,file"
|
|
69
|
+
@config.preserve_roles = true
|
|
70
|
+
task = new_task(:testing,@config, :roles => :app)
|
|
71
|
+
assert_equal %w(app1 app2 app3).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
|
72
|
+
ensure
|
|
73
|
+
ENV.delete('ROLES')
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_task_with_roles_as_environment_variable_and_preserve_roles_should_apply_only_to_existant_task_roles
|
|
77
|
+
ENV['ROLES'] = "app,file,web"
|
|
78
|
+
@config.preserve_roles = true
|
|
79
|
+
task = new_task(:testing,@config, :roles => [ :app,:file ])
|
|
80
|
+
assert_equal %w(app1 app2 app3 file).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
|
81
|
+
ensure
|
|
82
|
+
ENV.delete('ROLES')
|
|
56
83
|
end
|
|
57
84
|
|
|
85
|
+
def test_task_with_roles_as_environment_variable_and_preserve_roles_should_not_apply_if_not_exists_those_task_roles
|
|
86
|
+
ENV['ROLES'] = "file,web"
|
|
87
|
+
@config.preserve_roles = true
|
|
88
|
+
task = new_task(:testing,@config, :roles => [ :app ])
|
|
89
|
+
assert_equal [], @config.find_servers_for_task(task).map { |s| s.host }.sort
|
|
90
|
+
ensure
|
|
91
|
+
ENV.delete('ROLES')
|
|
92
|
+
end
|
|
93
|
+
|
|
58
94
|
def test_task_with_hosts_as_environment_variable_should_apply_only_to_those_hosts
|
|
59
95
|
ENV['HOSTS'] = "foo,bar"
|
|
60
96
|
task = new_task(:testing)
|
|
61
97
|
assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
|
62
98
|
ensure
|
|
63
|
-
ENV
|
|
99
|
+
ENV.delete('HOSTS')
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_task_with_hosts_as_environment_variable_should_not_inspect_roles_at_all
|
|
103
|
+
ENV['HOSTS'] = "foo,bar"
|
|
104
|
+
task = new_task(:testing, @config, :roles => :bogus)
|
|
105
|
+
assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
|
106
|
+
ensure
|
|
107
|
+
ENV.delete('HOSTS')
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_task_with_hostfilter_environment_variable_should_apply_only_to_those_hosts
|
|
111
|
+
ENV['HOSTFILTER'] = "app1,web1"
|
|
112
|
+
task = new_task(:testing)
|
|
113
|
+
assert_equal %w(app1 web1).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
|
114
|
+
ensure
|
|
115
|
+
ENV.delete('HOSTFILTER')
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def test_task_with_hostfilter_environment_variable_should_filter_hosts_option
|
|
119
|
+
ENV['HOSTFILTER'] = "foo"
|
|
120
|
+
task = new_task(:testing, @config, :hosts => %w(foo bar))
|
|
121
|
+
assert_equal %w(foo).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
|
122
|
+
ensure
|
|
123
|
+
ENV.delete('HOSTFILTER')
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def test_task_with_hostfilter_environment_variable_and_skip_hostfilter_should_not_filter_hosts_option
|
|
127
|
+
ENV['HOSTFILTER'] = "foo"
|
|
128
|
+
task = new_task(:testing, @config, :hosts => %w(foo bar), :skip_hostfilter => true)
|
|
129
|
+
assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
|
130
|
+
ensure
|
|
131
|
+
ENV.delete('HOSTFILTER')
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_task_with_hostrolefilter_environment_variable_should_apply_only_to_those_hosts
|
|
135
|
+
ENV['HOSTROLEFILTER'] = "web"
|
|
136
|
+
task = new_task(:testing)
|
|
137
|
+
assert_equal %w(web1 web2).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
|
|
138
|
+
ensure
|
|
139
|
+
ENV.delete('HOSTROLEFILTER')
|
|
64
140
|
end
|
|
65
141
|
|
|
66
142
|
def test_task_with_only_should_apply_only_to_matching_tasks
|
|
@@ -87,4 +163,21 @@ class ConfigurationServersTest < Test::Unit::TestCase
|
|
|
87
163
|
assert_equal %w(app1 app2 app3), @config.find_servers(:roles => lambda { :app }).map { |s| s.host }.sort
|
|
88
164
|
assert_equal %w(app2 file), @config.find_servers(:roles => lambda { [:report, :file] }).map { |s| s.host }.sort
|
|
89
165
|
end
|
|
90
|
-
|
|
166
|
+
|
|
167
|
+
def test_find_servers_with_hosts_nil_or_empty
|
|
168
|
+
assert_equal [], @config.find_servers(:hosts => nil)
|
|
169
|
+
assert_equal [], @config.find_servers(:hosts => [])
|
|
170
|
+
result = @config.find_servers(:hosts => @config.find_servers(:roles => :report)[0])
|
|
171
|
+
assert_equal 1, result.size
|
|
172
|
+
result = @config.find_servers(:hosts => "app1")
|
|
173
|
+
assert_equal 1, result.size
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def test_find_servers_with_rolees_nil_or_empty
|
|
177
|
+
assert_equal [], @config.find_servers(:roles => nil)
|
|
178
|
+
assert_equal [], @config.find_servers(:roles => [])
|
|
179
|
+
result = @config.find_servers(:roles => :report)
|
|
180
|
+
assert_equal 1, result.size
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "utils"
|
|
2
2
|
require 'capistrano/configuration/variables'
|
|
3
3
|
|
|
4
4
|
class ConfigurationVariablesTest < Test::Unit::TestCase
|
|
@@ -54,6 +54,16 @@ class ConfigurationVariablesTest < Test::Unit::TestCase
|
|
|
54
54
|
assert @config.respond_to?(:sample)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
+
def test_respond_to_should_be_true_when_passed_a_string
|
|
58
|
+
assert !@config.respond_to?('sample')
|
|
59
|
+
@config[:sample] = :value
|
|
60
|
+
assert @config.respond_to?('sample')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_respond_to_with_include_priv_paramter
|
|
64
|
+
assert !@config.respond_to?(:sample, true)
|
|
65
|
+
end
|
|
66
|
+
|
|
57
67
|
def test_set_should_require_value
|
|
58
68
|
assert_raises(ArgumentError) do
|
|
59
69
|
@config.set(:sample)
|
|
@@ -177,4 +187,4 @@ class ConfigurationVariablesTest < Test::Unit::TestCase
|
|
|
177
187
|
assert_nil @config[:sample]
|
|
178
188
|
end
|
|
179
189
|
end
|
|
180
|
-
end
|
|
190
|
+
end
|
data/test/configuration_test.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "utils"
|
|
2
2
|
require 'capistrano/configuration'
|
|
3
3
|
|
|
4
4
|
# These tests are only for testing the integration of the various components
|
|
@@ -12,7 +12,14 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
|
12
12
|
|
|
13
13
|
def test_connections_execution_loading_namespaces_roles_and_variables_modules_should_integrate_correctly
|
|
14
14
|
Capistrano::SSH.expects(:connect).with { |s,c| s.host == "www.capistrano.test" && c == @config }.returns(:session)
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
process_args = Proc.new do |tree, session, opts|
|
|
17
|
+
tree.fallback.command == "echo 'hello world'" &&
|
|
18
|
+
session == [:session] &&
|
|
19
|
+
opts == { :logger => @config.logger, :eof => true }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
Capistrano::Command.expects(:process).with(&process_args)
|
|
16
23
|
|
|
17
24
|
@config.load do
|
|
18
25
|
role :test, "www.capistrano.test"
|
|
@@ -67,15 +74,4 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
|
67
74
|
assert !@config[:called_inner_first]
|
|
68
75
|
end
|
|
69
76
|
|
|
70
|
-
def test_hooks_for_default_task_should_be_found_if_named_after_the_namespace
|
|
71
|
-
@config.namespace(:outer) do
|
|
72
|
-
task(:default) { set :called_default, true }
|
|
73
|
-
task(:before_outer) { set :called_before_outer, true }
|
|
74
|
-
task(:after_outer) { set :called_after_outer, true }
|
|
75
|
-
end
|
|
76
|
-
@config.outer.default
|
|
77
|
-
assert @config[:called_before_outer]
|
|
78
|
-
assert @config[:called_default]
|
|
79
|
-
assert @config[:called_after_outer]
|
|
80
|
-
end
|
|
81
77
|
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require "utils"
|
|
2
|
+
require 'capistrano/recipes/deploy/local_dependency'
|
|
3
|
+
|
|
4
|
+
class LocalDependencyTest < Test::Unit::TestCase
|
|
5
|
+
def setup
|
|
6
|
+
@config = { }
|
|
7
|
+
@dependency = Capistrano::Deploy::LocalDependency.new(@config)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_should_use_standard_error_message
|
|
11
|
+
setup_for_one_path_entry(false)
|
|
12
|
+
@dependency.command("cat")
|
|
13
|
+
assert_equal "`cat' could not be found in the path on the local host", @dependency.message
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_should_use_alternative_message_if_provided
|
|
17
|
+
setup_for_one_path_entry(false)
|
|
18
|
+
@dependency.command("cat").or("Sorry")
|
|
19
|
+
assert_equal "Sorry", @dependency.message
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_env_with_no_path_should_never_find_command
|
|
23
|
+
ENV.expects(:[]).with("PATH").returns(nil)
|
|
24
|
+
assert !@dependency.command("cat").pass?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_env_with_one_path_entry_should_fail_if_command_not_found
|
|
28
|
+
setup_for_one_path_entry(false)
|
|
29
|
+
assert !@dependency.command("cat").pass?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_env_with_one_path_entry_should_pass_if_command_found
|
|
33
|
+
setup_for_one_path_entry(true)
|
|
34
|
+
assert @dependency.command("cat").pass?
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_env_with_three_path_entries_should_fail_if_command_not_found
|
|
38
|
+
setup_for_three_path_entries(false)
|
|
39
|
+
assert !@dependency.command("cat").pass?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_env_with_three_path_entries_should_pass_if_command_found
|
|
43
|
+
setup_for_three_path_entries(true)
|
|
44
|
+
assert @dependency.command("cat").pass?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_env_with_one_path_entry_on_windows_should_pass_if_command_found_with_extension
|
|
48
|
+
setup_for_one_path_entry_on_windows(true)
|
|
49
|
+
assert @dependency.command("cat").pass?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def setup_for_one_path_entry(command_found)
|
|
55
|
+
Capistrano::Deploy::LocalDependency.expects(:on_windows?).returns(false)
|
|
56
|
+
ENV.expects(:[]).with("PATH").returns("/bin")
|
|
57
|
+
File.expects(:executable?).with("/bin/cat").returns(command_found)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def setup_for_three_path_entries(command_found)
|
|
61
|
+
Capistrano::Deploy::LocalDependency.expects(:on_windows?).returns(false)
|
|
62
|
+
path = %w(/bin /usr/bin /usr/local/bin).join(File::PATH_SEPARATOR)
|
|
63
|
+
ENV.expects(:[]).with("PATH").returns(path)
|
|
64
|
+
File.expects(:executable?).with("/usr/bin/cat").returns(command_found)
|
|
65
|
+
File.expects(:executable?).at_most(1).with("/bin/cat").returns(false)
|
|
66
|
+
File.expects(:executable?).at_most(1).with("/usr/local/bin/cat").returns(false)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def setup_for_one_path_entry_on_windows(command_found)
|
|
70
|
+
Capistrano::Deploy::LocalDependency.expects(:on_windows?).returns(true)
|
|
71
|
+
ENV.expects(:[]).with("PATH").returns("/cygwin/bin")
|
|
72
|
+
File.stubs(:executable?).returns(false)
|
|
73
|
+
first_executable_extension = Capistrano::Deploy::LocalDependency.windows_executable_extensions.first
|
|
74
|
+
File.expects(:executable?).with("/cygwin/bin/cat#{first_executable_extension}").returns(command_found)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
require "utils"
|
|
2
|
+
require 'capistrano/recipes/deploy/remote_dependency'
|
|
3
|
+
|
|
4
|
+
class RemoteDependencyTest < Test::Unit::TestCase
|
|
5
|
+
def setup
|
|
6
|
+
@config = { }
|
|
7
|
+
@dependency = Capistrano::Deploy::RemoteDependency.new(@config)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_should_use_standard_error_message_for_directory
|
|
11
|
+
setup_for_a_configuration_run("test -d /data", false)
|
|
12
|
+
@dependency.directory("/data")
|
|
13
|
+
assert_equal "`/data' is not a directory (host)", @dependency.message
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_should_use_standard_error_message_for_file
|
|
17
|
+
setup_for_a_configuration_run("test -f /data/foo.txt", false)
|
|
18
|
+
@dependency.file("/data/foo.txt")
|
|
19
|
+
assert_equal "`/data/foo.txt' is not a file (host)", @dependency.message
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_should_use_standard_error_message_for_writable
|
|
23
|
+
setup_for_a_configuration_run("test -w /data/foo.txt", false)
|
|
24
|
+
@dependency.writable("/data/foo.txt")
|
|
25
|
+
assert_equal "`/data/foo.txt' is not writable (host)", @dependency.message
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_should_use_standard_error_message_for_command
|
|
29
|
+
setup_for_a_configuration_run("which cat", false)
|
|
30
|
+
@dependency.command("cat")
|
|
31
|
+
assert_equal "`cat' could not be found in the path (host)", @dependency.message
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_should_use_standard_error_message_for_gem
|
|
35
|
+
setup_for_a_configuration_gem_run("capistrano", "9.9", false)
|
|
36
|
+
@dependency.gem("capistrano", 9.9)
|
|
37
|
+
assert_equal "gem `capistrano' 9.9 could not be found (host)", @dependency.message
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_should_use_standard_error_message_for_deb
|
|
41
|
+
setup_for_a_configuration_deb_run("dpkg", "1.15", false)
|
|
42
|
+
@dependency.deb("dpkg", "1.15")
|
|
43
|
+
assert_equal "package `dpkg' 1.15 could not be found (host)", @dependency.message
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_should_use_standard_error_message_for_rpm
|
|
47
|
+
setup_for_a_configuration_rpm_run("rpm", "4.8", false)
|
|
48
|
+
@dependency.rpm("rpm", "4.8")
|
|
49
|
+
assert_equal "package `rpm' 4.8 could not be found (host)", @dependency.message
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_should_fail_if_directory_not_found
|
|
53
|
+
setup_for_a_configuration_run("test -d /data", false)
|
|
54
|
+
assert !@dependency.directory("/data").pass?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_should_pass_if_directory_found
|
|
58
|
+
setup_for_a_configuration_run("test -d /data", true)
|
|
59
|
+
assert @dependency.directory("/data").pass?
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_should_fail_if_file_not_found
|
|
63
|
+
setup_for_a_configuration_run("test -f /data/foo.txt", false)
|
|
64
|
+
assert !@dependency.file("/data/foo.txt").pass?
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_should_pass_if_file_found
|
|
68
|
+
setup_for_a_configuration_run("test -f /data/foo.txt", true)
|
|
69
|
+
assert @dependency.file("/data/foo.txt").pass?
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_should_fail_if_writable_not_found
|
|
73
|
+
setup_for_a_configuration_run("test -w /data/foo.txt", false)
|
|
74
|
+
assert !@dependency.writable("/data/foo.txt").pass?
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_should_pass_if_writable_found
|
|
78
|
+
setup_for_a_configuration_run("test -w /data/foo.txt", true)
|
|
79
|
+
assert @dependency.writable("/data/foo.txt").pass?
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_should_fail_if_command_not_found
|
|
83
|
+
setup_for_a_configuration_run("which cat", false)
|
|
84
|
+
assert !@dependency.command("cat").pass?
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_should_pass_if_command_found
|
|
88
|
+
setup_for_a_configuration_run("which cat", true)
|
|
89
|
+
assert @dependency.command("cat").pass?
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_should_fail_if_gem_not_found
|
|
93
|
+
setup_for_a_configuration_gem_run("capistrano", "9.9", false)
|
|
94
|
+
assert !@dependency.gem("capistrano", 9.9).pass?
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_should_pass_if_gem_found
|
|
98
|
+
setup_for_a_configuration_gem_run("capistrano", "9.9", true)
|
|
99
|
+
assert @dependency.gem("capistrano", 9.9).pass?
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_should_pass_if_deb_found
|
|
103
|
+
setup_for_a_configuration_deb_run("dpkg", "1.15", true)
|
|
104
|
+
assert @dependency.deb("dpkg", "1.15").pass?
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def test_should_fail_if_deb_not_found
|
|
108
|
+
setup_for_a_configuration_deb_run("dpkg", "1.15", false)
|
|
109
|
+
assert !@dependency.deb("dpkg", "1.15").pass?
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_should_use_alternative_message_if_provided
|
|
113
|
+
setup_for_a_configuration_run("which cat", false)
|
|
114
|
+
@dependency.command("cat").or("Sorry")
|
|
115
|
+
assert_equal "Sorry (host)", @dependency.message
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
private
|
|
119
|
+
|
|
120
|
+
def setup_for_a_configuration_run(command, passing)
|
|
121
|
+
expectation = @config.expects(:invoke_command).with(command, {})
|
|
122
|
+
if passing
|
|
123
|
+
expectation.returns(true)
|
|
124
|
+
else
|
|
125
|
+
error = Capistrano::CommandError.new
|
|
126
|
+
error.expects(:hosts).returns(["host"])
|
|
127
|
+
expectation.raises(error)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def setup_for_a_configuration_gem_run(name, version, passing)
|
|
132
|
+
@config.expects(:fetch).with(:gem_command, "gem").returns("gem")
|
|
133
|
+
find_gem_cmd = "gem specification --version '#{version}' #{name} 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }'"
|
|
134
|
+
setup_for_a_configuration_run(find_gem_cmd, passing)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def setup_for_a_configuration_deb_run(name, version, passing)
|
|
138
|
+
find_deb_cmd = "dpkg -s #{name} | grep '^Version: #{version}'"
|
|
139
|
+
setup_for_a_configuration_run(find_deb_cmd, passing)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def setup_for_a_configuration_rpm_run(name, version, passing)
|
|
143
|
+
find_rpm_cmd = "rpm -q #{name} | grep '#{version}'"
|
|
144
|
+
setup_for_a_configuration_run(find_rpm_cmd, passing)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "utils"
|
|
2
|
+
require 'capistrano/recipes/deploy/scm/accurev'
|
|
3
|
+
|
|
4
|
+
class AccurevTest < Test::Unit::TestCase
|
|
5
|
+
include Capistrano::Deploy::SCM
|
|
6
|
+
|
|
7
|
+
def test_internal_revision_to_s
|
|
8
|
+
assert_equal 'foo/1', Accurev::InternalRevision.new('foo', 1).to_s
|
|
9
|
+
assert_equal 'foo/highest', Accurev::InternalRevision.new('foo', 'highest').to_s
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_internal_revision_parse
|
|
13
|
+
revision = Accurev::InternalRevision.parse('foo')
|
|
14
|
+
assert_equal 'foo', revision.stream
|
|
15
|
+
assert_equal 'highest', revision.transaction_id
|
|
16
|
+
assert_equal 'foo/highest', revision.to_s
|
|
17
|
+
|
|
18
|
+
revision = Accurev::InternalRevision.parse('foo/1')
|
|
19
|
+
assert_equal 'foo', revision.stream
|
|
20
|
+
assert_equal '1', revision.transaction_id
|
|
21
|
+
assert_equal 'foo/1', revision.to_s
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require "utils"
|
|
2
|
+
require 'capistrano/recipes/deploy/scm/bzr'
|
|
3
|
+
|
|
4
|
+
class DeploySCMBzrTest < Test::Unit::TestCase
|
|
5
|
+
class TestSCM < Capistrano::Deploy::SCM::Bzr
|
|
6
|
+
default_command "bzr"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
@config = { :repository => "." }
|
|
11
|
+
|
|
12
|
+
def @config.exists?(name); key?(name); end # is this actually needed?
|
|
13
|
+
|
|
14
|
+
@source = TestSCM.new(@config)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# The bzr scm does not support pseudo-ids. The bzr adapter uses symbol :head
|
|
18
|
+
# to refer to the recently committed revision.
|
|
19
|
+
def test_head_revision
|
|
20
|
+
assert_equal(:head,
|
|
21
|
+
@source.head,
|
|
22
|
+
"Since bzr doesn't know a real head revision, symbol :head is used instead.")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# The bzr scm does support many different ways to specify a revision. Only
|
|
26
|
+
# symbol :head triggers the bzr command 'revno'.
|
|
27
|
+
def test_query_revision
|
|
28
|
+
assert_equal("bzr revno #{@config[:repository]}",
|
|
29
|
+
@source.query_revision(:head) { |o| o },
|
|
30
|
+
"Query for :head revision should call bzr command 'revno' in repository directory.")
|
|
31
|
+
|
|
32
|
+
# Many valid revision specifications, some invalid on the last line
|
|
33
|
+
revision_samples = [ 5, -7, '2', '-4',
|
|
34
|
+
'revid:revid:aaaa@bbbb-123456789',
|
|
35
|
+
'submit:',
|
|
36
|
+
'ancestor:/path/to/branch',
|
|
37
|
+
'date:yesterday',
|
|
38
|
+
'branch:/path/to/branch',
|
|
39
|
+
'tag:trunk',
|
|
40
|
+
'revno:3:/path/to/branch',
|
|
41
|
+
'before:revid:aaaa@bbbb-1234567890',
|
|
42
|
+
'last:3',
|
|
43
|
+
nil, {}, [], true, false, 1.34, ]
|
|
44
|
+
|
|
45
|
+
revision_samples.each do |revivsion_spec|
|
|
46
|
+
assert_equal(revivsion_spec,
|
|
47
|
+
@source.query_revision(revivsion_spec),
|
|
48
|
+
"Any revision specification other than symbol :head should simply by returned.")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|