capistrano 2.0.0 → 2.15.2
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 +715 -18
- data/Gemfile +12 -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 +212 -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 +91 -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 +62 -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 +185 -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 +10 -8
- 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 +35 -17
- 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 +91 -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 +17 -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 +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 +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 +27 -33
- metadata +215 -102
- 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/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,32 +1,36 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "utils"
|
|
2
2
|
require 'capistrano/logger'
|
|
3
3
|
require 'capistrano/recipes/deploy/strategy/copy'
|
|
4
|
+
require 'stringio'
|
|
4
5
|
|
|
5
6
|
class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
6
7
|
def setup
|
|
7
|
-
@config = { :
|
|
8
|
+
@config = { :application => "captest",
|
|
8
9
|
:releases_path => "/u/apps/test/releases",
|
|
9
10
|
:release_path => "/u/apps/test/releases/1234567890",
|
|
10
11
|
:real_revision => "154" }
|
|
12
|
+
@config.stubs(:logger).returns(stub_everything)
|
|
13
|
+
|
|
11
14
|
@source = mock("source")
|
|
12
15
|
@config.stubs(:source).returns(@source)
|
|
13
16
|
@strategy = Capistrano::Deploy::Strategy::Copy.new(@config)
|
|
14
17
|
end
|
|
15
18
|
|
|
16
|
-
def
|
|
19
|
+
def test_deploy_with_defaults_should_use_remote_gtar
|
|
20
|
+
@config[:copy_remote_tar] = 'gtar'
|
|
21
|
+
|
|
17
22
|
Dir.expects(:tmpdir).returns("/temp/dir")
|
|
18
|
-
Dir.expects(:chdir).with("/temp/dir").yields
|
|
19
23
|
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
|
20
|
-
|
|
21
24
|
@strategy.expects(:system).with(:local_checkout)
|
|
25
|
+
|
|
26
|
+
Dir.expects(:chdir).with("/temp/dir").yields
|
|
22
27
|
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
|
23
|
-
@strategy.expects(:
|
|
24
|
-
@strategy.expects(:run).with("cd /u/apps/test/releases &&
|
|
28
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
|
|
29
|
+
@strategy.expects(:run).with("cd /u/apps/test/releases && gtar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
|
25
30
|
|
|
26
31
|
mock_file = mock("file")
|
|
27
32
|
mock_file.expects(:puts).with("154")
|
|
28
33
|
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
|
29
|
-
File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents)
|
|
30
34
|
|
|
31
35
|
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
|
32
36
|
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
|
@@ -34,21 +38,21 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
|
34
38
|
@strategy.deploy!
|
|
35
39
|
end
|
|
36
40
|
|
|
37
|
-
def
|
|
41
|
+
def test_deploy_with_defaults_should_use_local_gtar
|
|
42
|
+
@config[:copy_local_tar] = 'gtar'
|
|
43
|
+
|
|
38
44
|
Dir.expects(:tmpdir).returns("/temp/dir")
|
|
39
|
-
|
|
40
|
-
@
|
|
41
|
-
@source.expects(:export).with("154", "/temp/dir/1234567890").returns(:local_export)
|
|
45
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
|
46
|
+
@strategy.expects(:system).with(:local_checkout)
|
|
42
47
|
|
|
43
|
-
|
|
44
|
-
@strategy.expects(:system).with("
|
|
45
|
-
@strategy.expects(:
|
|
48
|
+
Dir.expects(:chdir).with("/temp/dir").yields
|
|
49
|
+
@strategy.expects(:system).with("gtar czf 1234567890.tar.gz 1234567890")
|
|
50
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
|
|
46
51
|
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
|
47
52
|
|
|
48
53
|
mock_file = mock("file")
|
|
49
54
|
mock_file.expects(:puts).with("154")
|
|
50
55
|
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
|
51
|
-
File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents)
|
|
52
56
|
|
|
53
57
|
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
|
54
58
|
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
|
@@ -56,6 +60,49 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
|
56
60
|
@strategy.deploy!
|
|
57
61
|
end
|
|
58
62
|
|
|
63
|
+
def test_deploy_with_defaults_should_use_tar_gz_and_checkout
|
|
64
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
|
65
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
|
66
|
+
@strategy.expects(:system).with(:local_checkout)
|
|
67
|
+
|
|
68
|
+
prepare_standard_compress_and_copy!
|
|
69
|
+
@strategy.deploy!
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_deploy_with_exclusions_should_remove_patterns_from_destination
|
|
73
|
+
@config[:copy_exclude] = ".git"
|
|
74
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
|
75
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
|
76
|
+
@strategy.expects(:system).with(:local_checkout)
|
|
77
|
+
Dir.expects(:glob).with("/temp/dir/1234567890/.git", File::FNM_DOTMATCH).returns(%w(/temp/dir/1234567890/.git))
|
|
78
|
+
|
|
79
|
+
FileUtils.expects(:rm_rf).with(%w(/temp/dir/1234567890/.git))
|
|
80
|
+
prepare_standard_compress_and_copy!
|
|
81
|
+
@strategy.deploy!
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_deploy_with_exclusions_should_remove_glob_patterns_from_destination
|
|
85
|
+
@config[:copy_exclude] = ".gi*"
|
|
86
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
|
87
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
|
88
|
+
@strategy.expects(:system).with(:local_checkout)
|
|
89
|
+
Dir.expects(:glob).with("/temp/dir/1234567890/.gi*", File::FNM_DOTMATCH).returns(%w(/temp/dir/1234567890/.git))
|
|
90
|
+
|
|
91
|
+
FileUtils.expects(:rm_rf).with(%w(/temp/dir/1234567890/.git))
|
|
92
|
+
prepare_standard_compress_and_copy!
|
|
93
|
+
@strategy.deploy!
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_deploy_with_export_should_use_tar_gz_and_export
|
|
97
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
|
98
|
+
@config[:copy_strategy] = :export
|
|
99
|
+
@source.expects(:export).with("154", "/temp/dir/1234567890").returns(:local_export)
|
|
100
|
+
@strategy.expects(:system).with(:local_export)
|
|
101
|
+
|
|
102
|
+
prepare_standard_compress_and_copy!
|
|
103
|
+
@strategy.deploy!
|
|
104
|
+
end
|
|
105
|
+
|
|
59
106
|
def test_deploy_with_zip_should_use_zip_and_checkout
|
|
60
107
|
Dir.expects(:tmpdir).returns("/temp/dir")
|
|
61
108
|
Dir.expects(:chdir).with("/temp/dir").yields
|
|
@@ -63,14 +110,13 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
|
63
110
|
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
|
64
111
|
|
|
65
112
|
@strategy.expects(:system).with(:local_checkout)
|
|
66
|
-
@strategy.expects(:system).with("zip -
|
|
67
|
-
@strategy.expects(:
|
|
113
|
+
@strategy.expects(:system).with("zip -qyr 1234567890.zip 1234567890")
|
|
114
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.zip", "/tmp/1234567890.zip")
|
|
68
115
|
@strategy.expects(:run).with("cd /u/apps/test/releases && unzip -q /tmp/1234567890.zip && rm /tmp/1234567890.zip")
|
|
69
116
|
|
|
70
117
|
mock_file = mock("file")
|
|
71
118
|
mock_file.expects(:puts).with("154")
|
|
72
119
|
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
|
73
|
-
File.expects(:read).with("/temp/dir/1234567890.zip").returns(:mock_file_contents)
|
|
74
120
|
|
|
75
121
|
FileUtils.expects(:rm).with("/temp/dir/1234567890.zip")
|
|
76
122
|
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
|
@@ -78,7 +124,7 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
|
78
124
|
@strategy.deploy!
|
|
79
125
|
end
|
|
80
126
|
|
|
81
|
-
def
|
|
127
|
+
def test_deploy_with_bzip2_should_use_bz2_and_checkout
|
|
82
128
|
Dir.expects(:tmpdir).returns("/temp/dir")
|
|
83
129
|
Dir.expects(:chdir).with("/temp/dir").yields
|
|
84
130
|
@config[:copy_compression] = :bzip2
|
|
@@ -86,13 +132,12 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
|
86
132
|
|
|
87
133
|
@strategy.expects(:system).with(:local_checkout)
|
|
88
134
|
@strategy.expects(:system).with("tar cjf 1234567890.tar.bz2 1234567890")
|
|
89
|
-
@strategy.expects(:
|
|
135
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.bz2", "/tmp/1234567890.tar.bz2")
|
|
90
136
|
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xjf /tmp/1234567890.tar.bz2 && rm /tmp/1234567890.tar.bz2")
|
|
91
137
|
|
|
92
138
|
mock_file = mock("file")
|
|
93
139
|
mock_file.expects(:puts).with("154")
|
|
94
140
|
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
|
95
|
-
File.expects(:read).with("/temp/dir/1234567890.tar.bz2").returns(:mock_file_contents)
|
|
96
141
|
|
|
97
142
|
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.bz2")
|
|
98
143
|
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
|
@@ -100,6 +145,16 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
|
100
145
|
@strategy.deploy!
|
|
101
146
|
end
|
|
102
147
|
|
|
148
|
+
def test_deploy_with_unknown_compression_type_should_error
|
|
149
|
+
@config[:copy_compression] = :bogus
|
|
150
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
|
151
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
|
152
|
+
@strategy.stubs(:system)
|
|
153
|
+
File.stubs(:open)
|
|
154
|
+
|
|
155
|
+
assert_raises(ArgumentError) { @strategy.deploy! }
|
|
156
|
+
end
|
|
157
|
+
|
|
103
158
|
def test_deploy_with_custom_copy_dir_should_use_that_as_tmpdir
|
|
104
159
|
Dir.expects(:tmpdir).never
|
|
105
160
|
Dir.expects(:chdir).with("/other/path").yields
|
|
@@ -108,13 +163,12 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
|
108
163
|
|
|
109
164
|
@strategy.expects(:system).with(:local_checkout)
|
|
110
165
|
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
|
111
|
-
@strategy.expects(:
|
|
166
|
+
@strategy.expects(:upload).with("/other/path/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
|
|
112
167
|
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
|
113
168
|
|
|
114
169
|
mock_file = mock("file")
|
|
115
170
|
mock_file.expects(:puts).with("154")
|
|
116
171
|
File.expects(:open).with("/other/path/1234567890/REVISION", "w").yields(mock_file)
|
|
117
|
-
File.expects(:read).with("/other/path/1234567890.tar.gz").returns(:mock_file_contents)
|
|
118
172
|
|
|
119
173
|
FileUtils.expects(:rm).with("/other/path/1234567890.tar.gz")
|
|
120
174
|
FileUtils.expects(:rm_rf).with("/other/path/1234567890")
|
|
@@ -130,17 +184,177 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
|
130
184
|
|
|
131
185
|
@strategy.expects(:system).with(:local_checkout)
|
|
132
186
|
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
|
133
|
-
@strategy.expects(:
|
|
187
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/somewhere/else/1234567890.tar.gz")
|
|
134
188
|
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /somewhere/else/1234567890.tar.gz && rm /somewhere/else/1234567890.tar.gz")
|
|
135
189
|
|
|
136
190
|
mock_file = mock("file")
|
|
137
191
|
mock_file.expects(:puts).with("154")
|
|
138
192
|
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
|
139
|
-
File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents)
|
|
140
193
|
|
|
141
194
|
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
|
142
195
|
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
|
143
196
|
|
|
144
197
|
@strategy.deploy!
|
|
145
198
|
end
|
|
199
|
+
|
|
200
|
+
def test_deploy_with_copy_via_should_use_the_given_transfer_method
|
|
201
|
+
@config[:copy_via] = :scp
|
|
202
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
|
203
|
+
Dir.expects(:chdir).yields
|
|
204
|
+
@source.expects(:checkout).returns(:local_checkout)
|
|
205
|
+
|
|
206
|
+
@strategy.expects(:system).with(:local_checkout)
|
|
207
|
+
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
|
208
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz", {:via => :scp})
|
|
209
|
+
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
|
210
|
+
|
|
211
|
+
mock_file = mock("file")
|
|
212
|
+
mock_file.expects(:puts).with("154")
|
|
213
|
+
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
|
214
|
+
|
|
215
|
+
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
|
216
|
+
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
|
217
|
+
|
|
218
|
+
@strategy.deploy!
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def test_with_copy_cache_should_checkout_to_cache_if_cache_does_not_exist_and_then_copy
|
|
222
|
+
@config[:copy_cache] = true
|
|
223
|
+
|
|
224
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
|
225
|
+
File.expects(:exists?).with("/temp/dir/captest").returns(false)
|
|
226
|
+
Dir.expects(:chdir).with("/temp/dir/captest").yields
|
|
227
|
+
|
|
228
|
+
@source.expects(:checkout).with("154", "/temp/dir/captest").returns(:local_checkout)
|
|
229
|
+
@strategy.expects(:system).with(:local_checkout)
|
|
230
|
+
|
|
231
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
|
232
|
+
|
|
233
|
+
prepare_directory_tree!("/temp/dir/captest")
|
|
234
|
+
|
|
235
|
+
prepare_standard_compress_and_copy!
|
|
236
|
+
@strategy.deploy!
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def test_with_copy_cache_should_update_cache_if_cache_exists_and_then_copy
|
|
240
|
+
@config[:copy_cache] = true
|
|
241
|
+
|
|
242
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
|
243
|
+
File.expects(:exists?).with("/temp/dir/captest").returns(true)
|
|
244
|
+
Dir.expects(:chdir).with("/temp/dir/captest").yields
|
|
245
|
+
|
|
246
|
+
@source.expects(:sync).with("154", "/temp/dir/captest").returns(:local_sync)
|
|
247
|
+
@strategy.expects(:system).with(:local_sync)
|
|
248
|
+
|
|
249
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
|
250
|
+
|
|
251
|
+
prepare_directory_tree!("/temp/dir/captest")
|
|
252
|
+
|
|
253
|
+
prepare_standard_compress_and_copy!
|
|
254
|
+
@strategy.deploy!
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def test_with_copy_cache_with_custom_absolute_cache_dir_path_should_use_specified_cache_dir
|
|
258
|
+
@config[:copy_cache] = "/u/caches/captest"
|
|
259
|
+
|
|
260
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
|
261
|
+
File.expects(:exists?).with("/u/caches/captest").returns(true)
|
|
262
|
+
Dir.expects(:chdir).with("/u/caches/captest").yields
|
|
263
|
+
|
|
264
|
+
@source.expects(:sync).with("154", "/u/caches/captest").returns(:local_sync)
|
|
265
|
+
@strategy.expects(:system).with(:local_sync)
|
|
266
|
+
|
|
267
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
|
268
|
+
|
|
269
|
+
prepare_directory_tree!("/u/caches/captest")
|
|
270
|
+
|
|
271
|
+
prepare_standard_compress_and_copy!
|
|
272
|
+
@strategy.deploy!
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def test_with_copy_cache_with_custom_relative_cache_dir_path_should_use_specified_cache_dir
|
|
276
|
+
@config[:copy_cache] = "caches/captest"
|
|
277
|
+
|
|
278
|
+
Dir.stubs(:pwd).returns("/u")
|
|
279
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
|
280
|
+
File.expects(:exists?).with("/u/caches/captest").returns(true)
|
|
281
|
+
Dir.expects(:chdir).with("/u/caches/captest").yields
|
|
282
|
+
|
|
283
|
+
@source.expects(:sync).with("154", "/u/caches/captest").returns(:local_sync)
|
|
284
|
+
@strategy.expects(:system).with(:local_sync)
|
|
285
|
+
|
|
286
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
|
287
|
+
|
|
288
|
+
prepare_directory_tree!("/u/caches/captest")
|
|
289
|
+
|
|
290
|
+
prepare_standard_compress_and_copy!
|
|
291
|
+
@strategy.deploy!
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
def test_with_copy_cache_with_excludes_should_not_copy_excluded_files
|
|
295
|
+
@config[:copy_cache] = true
|
|
296
|
+
@config[:copy_exclude] = "*/bar.txt"
|
|
297
|
+
|
|
298
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
|
299
|
+
File.expects(:exists?).with("/temp/dir/captest").returns(true)
|
|
300
|
+
Dir.expects(:chdir).with("/temp/dir/captest").yields
|
|
301
|
+
|
|
302
|
+
@source.expects(:sync).with("154", "/temp/dir/captest").returns(:local_sync)
|
|
303
|
+
@strategy.expects(:system).with(:local_sync)
|
|
304
|
+
|
|
305
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
|
306
|
+
|
|
307
|
+
prepare_directory_tree!("/temp/dir/captest", true)
|
|
308
|
+
|
|
309
|
+
prepare_standard_compress_and_copy!
|
|
310
|
+
@strategy.deploy!
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
def test_with_build_script_should_run_script
|
|
314
|
+
@config[:build_script] = "mkdir bin"
|
|
315
|
+
|
|
316
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
|
317
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
|
318
|
+
@strategy.expects(:system).with(:local_checkout)
|
|
319
|
+
|
|
320
|
+
Dir.expects(:chdir).with("/temp/dir/1234567890").yields
|
|
321
|
+
@strategy.expects(:system).with("mkdir bin")
|
|
322
|
+
|
|
323
|
+
prepare_standard_compress_and_copy!
|
|
324
|
+
@strategy.deploy!
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
private
|
|
328
|
+
|
|
329
|
+
def prepare_directory_tree!(cache, exclude=false)
|
|
330
|
+
Dir.expects(:glob).with("*", File::FNM_DOTMATCH).returns([".", "..", "app", "app{1}", "foo.txt"])
|
|
331
|
+
File.expects(:ftype).with("app").returns("directory")
|
|
332
|
+
File.expects(:ftype).with("app{1}").returns("directory")
|
|
333
|
+
FileUtils.expects(:mkdir).with("/temp/dir/1234567890/app")
|
|
334
|
+
FileUtils.expects(:mkdir).with("/temp/dir/1234567890/app{1}")
|
|
335
|
+
File.expects(:ftype).with("foo.txt").returns("file")
|
|
336
|
+
FileUtils.expects(:ln).with("foo.txt", "/temp/dir/1234567890/foo.txt")
|
|
337
|
+
|
|
338
|
+
Dir.expects(:glob).with("app/*", File::FNM_DOTMATCH).returns(["app/.", "app/..", "app/bar.txt"])
|
|
339
|
+
Dir.expects(:glob).with("app\\{1\\}/*", File::FNM_DOTMATCH).returns(["app{1}/.", "app{1}/.."])
|
|
340
|
+
|
|
341
|
+
unless exclude
|
|
342
|
+
File.expects(:ftype).with("app/bar.txt").returns("file")
|
|
343
|
+
FileUtils.expects(:ln).with("app/bar.txt", "/temp/dir/1234567890/app/bar.txt")
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
def prepare_standard_compress_and_copy!
|
|
348
|
+
Dir.expects(:chdir).with("/temp/dir").yields
|
|
349
|
+
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
|
350
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
|
|
351
|
+
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
|
352
|
+
|
|
353
|
+
mock_file = mock("file")
|
|
354
|
+
mock_file.expects(:puts).with("154")
|
|
355
|
+
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
|
356
|
+
|
|
357
|
+
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
|
358
|
+
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
|
359
|
+
end
|
|
146
360
|
end
|
data/test/extensions_test.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "utils"
|
|
2
2
|
require 'capistrano'
|
|
3
3
|
|
|
4
4
|
class ExtensionsTest < Test::Unit::TestCase
|
|
@@ -66,4 +66,4 @@ class ExtensionsTest < Test::Unit::TestCase
|
|
|
66
66
|
@config.expects(:run).with("hello")
|
|
67
67
|
@config.custom_stuff.do_something("hello")
|
|
68
68
|
end
|
|
69
|
-
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
require File.expand_path("../utils", __FILE__)
|
|
2
|
+
require 'capistrano/logger'
|
|
3
|
+
require 'stringio'
|
|
4
|
+
|
|
5
|
+
Capistrano::Logger.class_eval do
|
|
6
|
+
# Allows formatters to be changed during tests
|
|
7
|
+
def self.formatters=(formatters)
|
|
8
|
+
@formatters = formatters
|
|
9
|
+
@sorted_formatters = nil
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class LoggerFormattingTest < Test::Unit::TestCase
|
|
14
|
+
def setup
|
|
15
|
+
@io = StringIO.new
|
|
16
|
+
@io.stubs(:tty?).returns(true)
|
|
17
|
+
@logger = Capistrano::Logger.new(:output => @io, :level => 3)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_matching_with_style_and_color
|
|
21
|
+
Capistrano::Logger.formatters = [{ :match => /^err ::/, :color => :red, :style => :underscore, :level => 0 }]
|
|
22
|
+
@logger.log(0, "err :: Error Occurred")
|
|
23
|
+
assert @io.string.include? "\e[4;31merr :: Error Occurred\e[0m"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_style_without_color
|
|
27
|
+
Capistrano::Logger.formatters = [{ :match => /.*/, :style => :underscore, :level => 0 }]
|
|
28
|
+
@logger.log(0, "test message")
|
|
29
|
+
# Default color should be blank (0m)
|
|
30
|
+
assert @io.string.include? "\e[4;0mtest message\e[0m"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_prepending_text
|
|
34
|
+
Capistrano::Logger.formatters = [{ :match => /^executing/, :level => 0, :prepend => '== Currently ' }]
|
|
35
|
+
@logger.log(0, "executing task")
|
|
36
|
+
assert @io.string.include? '== Currently executing task'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_replacing_matched_text
|
|
40
|
+
Capistrano::Logger.formatters = [{ :match => /^executing/, :level => 0, :replace => 'running' }]
|
|
41
|
+
@logger.log(0, "executing task")
|
|
42
|
+
assert @io.string.include? 'running task'
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_prepending_timestamps
|
|
46
|
+
Capistrano::Logger.formatters = [{ :match => /.*/, :level => 0, :timestamp => true }]
|
|
47
|
+
@logger.log(0, "test message")
|
|
48
|
+
assert @io.string.match /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} test message/
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_formatter_priorities
|
|
52
|
+
Capistrano::Logger.formatters = [
|
|
53
|
+
{ :match => /.*/, :color => :red, :level => 0, :priority => -10 },
|
|
54
|
+
{ :match => /.*/, :color => :blue, :level => 0, :priority => -20, :prepend => '###' }
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
@logger.log(0, "test message")
|
|
58
|
+
# Only the red formatter (color 31) should be applied.
|
|
59
|
+
assert @io.string.include? "\e[31mtest message"
|
|
60
|
+
# The blue formatter should not have prepended $$$
|
|
61
|
+
assert !@io.string.include?('###')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_no_formatting_if_no_color_or_style
|
|
65
|
+
Capistrano::Logger.formatters = []
|
|
66
|
+
@logger.log(0, "test message")
|
|
67
|
+
assert @io.string.include? "*** test message"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_formatter_log_levels
|
|
71
|
+
Capistrano::Logger.formatters = [{ :match => /.*/, :color => :blue, :level => 3 }]
|
|
72
|
+
@logger.log(0, "test message")
|
|
73
|
+
# Should not match log level
|
|
74
|
+
assert @io.string.include? "*** test message"
|
|
75
|
+
|
|
76
|
+
clear_logger
|
|
77
|
+
@logger.log(3, "test message")
|
|
78
|
+
# Should match log level and apply blue color
|
|
79
|
+
assert @io.string.include? "\e[34mtest message"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private
|
|
83
|
+
|
|
84
|
+
def colorize(message, color, style = nil)
|
|
85
|
+
style = "#{style};" if style
|
|
86
|
+
"\e[#{style}#{color}m" + message + "\e[0m"
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def clear_logger
|
|
90
|
+
@io = StringIO.new
|
|
91
|
+
@io.stubs(:tty?).returns(true)
|
|
92
|
+
@logger.device = @io
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
class DefaultLoggerFormattersTest < Test::Unit::TestCase
|
|
97
|
+
def setup
|
|
98
|
+
@expected_default_formatter_values = [
|
|
99
|
+
# TRACE
|
|
100
|
+
{ :match => /command finished/, :color => :white, :style => :dim, :level => 3, :priority => -10 },
|
|
101
|
+
{ :match => /executing locally/, :color => :yellow, :level => 3, :priority => -20 },
|
|
102
|
+
|
|
103
|
+
# DEBUG
|
|
104
|
+
{ :match => /executing `.*/, :color => :green, :level => 2, :priority => -10, :timestamp => true },
|
|
105
|
+
{ :match => /.*/, :color => :yellow, :level => 2, :priority => -30 },
|
|
106
|
+
|
|
107
|
+
# INFO
|
|
108
|
+
{ :match => /.*out\] (fatal:|ERROR:).*/, :color => :red, :level => 1, :priority => -10 },
|
|
109
|
+
{ :match => /Permission denied/, :color => :red, :level => 1, :priority => -20 },
|
|
110
|
+
{ :match => /sh: .+: command not found/, :color => :magenta, :level => 1, :priority => -30 },
|
|
111
|
+
|
|
112
|
+
# IMPORTANT
|
|
113
|
+
{ :match => /^err ::/, :color => :red, :level => 0, :priority => -10 },
|
|
114
|
+
{ :match => /.*/, :color => :blue, :level => 0, :priority => -20 }
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
@custom_default_formatter_values = [
|
|
118
|
+
{ :match => /.*/, :color => :white }
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def test_default_formatters_api
|
|
124
|
+
assert Capistrano::Logger.respond_to? :default_formatters
|
|
125
|
+
assert Capistrano::Logger.respond_to? :default_formatters=
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_default_formatters_values
|
|
129
|
+
assert_equal @expected_default_formatter_values, Capistrano::Logger.default_formatters
|
|
130
|
+
assert_equal @expected_default_formatter_values, Capistrano::Logger.instance_variable_get("@formatters")
|
|
131
|
+
assert_equal nil, Capistrano::Logger.instance_variable_get("@sorted_formatters")
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_set_default_formatters_values
|
|
135
|
+
# when given an array
|
|
136
|
+
Capistrano::Logger.default_formatters = @custom_default_formatter_values
|
|
137
|
+
|
|
138
|
+
assert_equal @custom_default_formatter_values, Capistrano::Logger.default_formatters
|
|
139
|
+
Capistrano::Logger.default_formatters = @custom_default_formatter_values
|
|
140
|
+
assert_equal @custom_default_formatter_values, Capistrano::Logger.instance_variable_get("@formatters")
|
|
141
|
+
assert_equal nil, Capistrano::Logger.instance_variable_get("@sorted_formatters")
|
|
142
|
+
|
|
143
|
+
# when given a single formatter values hash
|
|
144
|
+
Capistrano::Logger.default_formatters = @custom_default_formatter_values.first
|
|
145
|
+
|
|
146
|
+
assert_equal @custom_default_formatter_values, Capistrano::Logger.default_formatters
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
end
|
data/test/logger_test.rb
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "utils"
|
|
2
2
|
require 'capistrano/logger'
|
|
3
3
|
require 'stringio'
|
|
4
4
|
|
|
5
5
|
class LoggerTest < Test::Unit::TestCase
|
|
6
6
|
def setup
|
|
7
7
|
@io = StringIO.new
|
|
8
|
-
|
|
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)
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def test_logger_should_use_STDERR_by_default
|
|
@@ -13,6 +14,16 @@ class LoggerTest < Test::Unit::TestCase
|
|
|
13
14
|
assert_equal STDERR, logger.device
|
|
14
15
|
end
|
|
15
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
|
+
|
|
16
27
|
def test_logger_should_use_output_option_if_output_responds_to_puts
|
|
17
28
|
logger = Capistrano::Logger.new(:output => STDOUT)
|
|
18
29
|
assert_equal STDOUT, logger.device
|
|
@@ -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
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "utils"
|
|
2
2
|
require 'capistrano/server_definition'
|
|
3
3
|
|
|
4
4
|
class ServerDefinitionTest < Test::Unit::TestCase
|
|
@@ -63,6 +63,19 @@ class ServerDefinitionTest < Test::Unit::TestCase
|
|
|
63
63
|
assert_equal true, server.options[:primary]
|
|
64
64
|
end
|
|
65
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
|
+
|
|
66
79
|
def test_comparison_should_match_when_host_user_port_are_same
|
|
67
80
|
s1 = server("jamis@www.capistrano.test:8080")
|
|
68
81
|
s2 = server("www.capistrano.test", :user => "jamis", :port => 8080)
|
|
@@ -105,4 +118,4 @@ class ServerDefinitionTest < Test::Unit::TestCase
|
|
|
105
118
|
assert_equal "jamis@www.capistrano.test", server("jamis@www.capistrano.test").to_s
|
|
106
119
|
assert_equal "jamis@www.capistrano.test:1234", server("jamis@www.capistrano.test:1234").to_s
|
|
107
120
|
end
|
|
108
|
-
end
|
|
121
|
+
end
|