minmb-capistrano 2.15.4

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.
Files changed (119) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +7 -0
  3. data/CHANGELOG +1170 -0
  4. data/Gemfile +13 -0
  5. data/README.md +94 -0
  6. data/Rakefile +11 -0
  7. data/bin/cap +4 -0
  8. data/bin/capify +92 -0
  9. data/capistrano.gemspec +40 -0
  10. data/lib/capistrano.rb +5 -0
  11. data/lib/capistrano/callback.rb +45 -0
  12. data/lib/capistrano/cli.rb +47 -0
  13. data/lib/capistrano/cli/execute.rb +85 -0
  14. data/lib/capistrano/cli/help.rb +125 -0
  15. data/lib/capistrano/cli/help.txt +81 -0
  16. data/lib/capistrano/cli/options.rb +243 -0
  17. data/lib/capistrano/cli/ui.rb +40 -0
  18. data/lib/capistrano/command.rb +303 -0
  19. data/lib/capistrano/configuration.rb +57 -0
  20. data/lib/capistrano/configuration/actions/file_transfer.rb +50 -0
  21. data/lib/capistrano/configuration/actions/inspect.rb +46 -0
  22. data/lib/capistrano/configuration/actions/invocation.rb +329 -0
  23. data/lib/capistrano/configuration/alias_task.rb +26 -0
  24. data/lib/capistrano/configuration/callbacks.rb +147 -0
  25. data/lib/capistrano/configuration/connections.rb +237 -0
  26. data/lib/capistrano/configuration/execution.rb +142 -0
  27. data/lib/capistrano/configuration/loading.rb +205 -0
  28. data/lib/capistrano/configuration/log_formatters.rb +75 -0
  29. data/lib/capistrano/configuration/namespaces.rb +223 -0
  30. data/lib/capistrano/configuration/roles.rb +77 -0
  31. data/lib/capistrano/configuration/servers.rb +116 -0
  32. data/lib/capistrano/configuration/variables.rb +127 -0
  33. data/lib/capistrano/errors.rb +19 -0
  34. data/lib/capistrano/ext/multistage.rb +64 -0
  35. data/lib/capistrano/ext/string.rb +5 -0
  36. data/lib/capistrano/extensions.rb +57 -0
  37. data/lib/capistrano/fix_rake_deprecated_dsl.rb +8 -0
  38. data/lib/capistrano/logger.rb +166 -0
  39. data/lib/capistrano/processable.rb +57 -0
  40. data/lib/capistrano/recipes/compat.rb +32 -0
  41. data/lib/capistrano/recipes/deploy.rb +625 -0
  42. data/lib/capistrano/recipes/deploy/assets.rb +201 -0
  43. data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
  44. data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
  45. data/lib/capistrano/recipes/deploy/remote_dependency.rb +117 -0
  46. data/lib/capistrano/recipes/deploy/scm.rb +19 -0
  47. data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
  48. data/lib/capistrano/recipes/deploy/scm/base.rb +200 -0
  49. data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
  50. data/lib/capistrano/recipes/deploy/scm/cvs.rb +153 -0
  51. data/lib/capistrano/recipes/deploy/scm/darcs.rb +96 -0
  52. data/lib/capistrano/recipes/deploy/scm/git.rb +293 -0
  53. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
  54. data/lib/capistrano/recipes/deploy/scm/none.rb +55 -0
  55. data/lib/capistrano/recipes/deploy/scm/perforce.rb +152 -0
  56. data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
  57. data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
  58. data/lib/capistrano/recipes/deploy/strategy/base.rb +92 -0
  59. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
  60. data/lib/capistrano/recipes/deploy/strategy/copy.rb +338 -0
  61. data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
  62. data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
  63. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +57 -0
  64. data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +21 -0
  65. data/lib/capistrano/recipes/standard.rb +37 -0
  66. data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
  67. data/lib/capistrano/role.rb +102 -0
  68. data/lib/capistrano/server_definition.rb +56 -0
  69. data/lib/capistrano/shell.rb +265 -0
  70. data/lib/capistrano/ssh.rb +95 -0
  71. data/lib/capistrano/task_definition.rb +77 -0
  72. data/lib/capistrano/transfer.rb +218 -0
  73. data/lib/capistrano/version.rb +11 -0
  74. data/test/cli/execute_test.rb +132 -0
  75. data/test/cli/help_test.rb +165 -0
  76. data/test/cli/options_test.rb +329 -0
  77. data/test/cli/ui_test.rb +28 -0
  78. data/test/cli_test.rb +17 -0
  79. data/test/command_test.rb +322 -0
  80. data/test/configuration/actions/file_transfer_test.rb +61 -0
  81. data/test/configuration/actions/inspect_test.rb +76 -0
  82. data/test/configuration/actions/invocation_test.rb +288 -0
  83. data/test/configuration/alias_task_test.rb +118 -0
  84. data/test/configuration/callbacks_test.rb +201 -0
  85. data/test/configuration/connections_test.rb +439 -0
  86. data/test/configuration/execution_test.rb +175 -0
  87. data/test/configuration/loading_test.rb +148 -0
  88. data/test/configuration/namespace_dsl_test.rb +332 -0
  89. data/test/configuration/roles_test.rb +157 -0
  90. data/test/configuration/servers_test.rb +183 -0
  91. data/test/configuration/variables_test.rb +190 -0
  92. data/test/configuration_test.rb +77 -0
  93. data/test/deploy/local_dependency_test.rb +76 -0
  94. data/test/deploy/remote_dependency_test.rb +146 -0
  95. data/test/deploy/scm/accurev_test.rb +23 -0
  96. data/test/deploy/scm/base_test.rb +55 -0
  97. data/test/deploy/scm/bzr_test.rb +51 -0
  98. data/test/deploy/scm/darcs_test.rb +37 -0
  99. data/test/deploy/scm/git_test.rb +221 -0
  100. data/test/deploy/scm/mercurial_test.rb +134 -0
  101. data/test/deploy/scm/none_test.rb +35 -0
  102. data/test/deploy/scm/perforce_test.rb +23 -0
  103. data/test/deploy/scm/subversion_test.rb +40 -0
  104. data/test/deploy/strategy/copy_test.rb +360 -0
  105. data/test/extensions_test.rb +69 -0
  106. data/test/fixtures/cli_integration.rb +5 -0
  107. data/test/fixtures/config.rb +5 -0
  108. data/test/fixtures/custom.rb +3 -0
  109. data/test/logger_formatting_test.rb +149 -0
  110. data/test/logger_test.rb +134 -0
  111. data/test/recipes_test.rb +25 -0
  112. data/test/role_test.rb +11 -0
  113. data/test/server_definition_test.rb +121 -0
  114. data/test/shell_test.rb +96 -0
  115. data/test/ssh_test.rb +113 -0
  116. data/test/task_definition_test.rb +117 -0
  117. data/test/transfer_test.rb +168 -0
  118. data/test/utils.rb +37 -0
  119. metadata +316 -0
@@ -0,0 +1,360 @@
1
+ require "utils"
2
+ require 'capistrano/logger'
3
+ require 'capistrano/recipes/deploy/strategy/copy'
4
+ require 'stringio'
5
+
6
+ class DeployStrategyCopyTest < Test::Unit::TestCase
7
+ def setup
8
+ @config = { :application => "captest",
9
+ :releases_path => "/u/apps/test/releases",
10
+ :release_path => "/u/apps/test/releases/1234567890",
11
+ :real_revision => "154" }
12
+ @config.stubs(:logger).returns(stub_everything)
13
+
14
+ @source = mock("source")
15
+ @config.stubs(:source).returns(@source)
16
+ @strategy = Capistrano::Deploy::Strategy::Copy.new(@config)
17
+ end
18
+
19
+ def test_deploy_with_defaults_should_use_remote_gtar
20
+ @config[:copy_remote_tar] = 'gtar'
21
+
22
+ Dir.expects(:tmpdir).returns("/temp/dir")
23
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
24
+ @strategy.expects(:system).with(:local_checkout)
25
+
26
+ Dir.expects(:chdir).with("/temp/dir").yields
27
+ @strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
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")
30
+
31
+ mock_file = mock("file")
32
+ mock_file.expects(:puts).with("154")
33
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
34
+
35
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
36
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
37
+
38
+ @strategy.deploy!
39
+ end
40
+
41
+ def test_deploy_with_defaults_should_use_local_gtar
42
+ @config[:copy_local_tar] = 'gtar'
43
+
44
+ Dir.expects(:tmpdir).returns("/temp/dir")
45
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
46
+ @strategy.expects(:system).with(:local_checkout)
47
+
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")
51
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
52
+
53
+ mock_file = mock("file")
54
+ mock_file.expects(:puts).with("154")
55
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
56
+
57
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
58
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
59
+
60
+ @strategy.deploy!
61
+ end
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
+
106
+ def test_deploy_with_zip_should_use_zip_and_checkout
107
+ Dir.expects(:tmpdir).returns("/temp/dir")
108
+ Dir.expects(:chdir).with("/temp/dir").yields
109
+ @config[:copy_compression] = :zip
110
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
111
+
112
+ @strategy.expects(:system).with(:local_checkout)
113
+ @strategy.expects(:system).with("zip -qyr 1234567890.zip 1234567890")
114
+ @strategy.expects(:upload).with("/temp/dir/1234567890.zip", "/tmp/1234567890.zip")
115
+ @strategy.expects(:run).with("cd /u/apps/test/releases && unzip -q /tmp/1234567890.zip && rm /tmp/1234567890.zip")
116
+
117
+ mock_file = mock("file")
118
+ mock_file.expects(:puts).with("154")
119
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
120
+
121
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.zip")
122
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
123
+
124
+ @strategy.deploy!
125
+ end
126
+
127
+ def test_deploy_with_bzip2_should_use_bz2_and_checkout
128
+ Dir.expects(:tmpdir).returns("/temp/dir")
129
+ Dir.expects(:chdir).with("/temp/dir").yields
130
+ @config[:copy_compression] = :bzip2
131
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
132
+
133
+ @strategy.expects(:system).with(:local_checkout)
134
+ @strategy.expects(:system).with("tar cjf 1234567890.tar.bz2 1234567890")
135
+ @strategy.expects(:upload).with("/temp/dir/1234567890.tar.bz2", "/tmp/1234567890.tar.bz2")
136
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xjf /tmp/1234567890.tar.bz2 && rm /tmp/1234567890.tar.bz2")
137
+
138
+ mock_file = mock("file")
139
+ mock_file.expects(:puts).with("154")
140
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
141
+
142
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.bz2")
143
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
144
+
145
+ @strategy.deploy!
146
+ end
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
+
158
+ def test_deploy_with_custom_copy_dir_should_use_that_as_tmpdir
159
+ Dir.expects(:tmpdir).never
160
+ Dir.expects(:chdir).with("/other/path").yields
161
+ @config[:copy_dir] = "/other/path"
162
+ @source.expects(:checkout).with("154", "/other/path/1234567890").returns(:local_checkout)
163
+
164
+ @strategy.expects(:system).with(:local_checkout)
165
+ @strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
166
+ @strategy.expects(:upload).with("/other/path/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
167
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
168
+
169
+ mock_file = mock("file")
170
+ mock_file.expects(:puts).with("154")
171
+ File.expects(:open).with("/other/path/1234567890/REVISION", "w").yields(mock_file)
172
+
173
+ FileUtils.expects(:rm).with("/other/path/1234567890.tar.gz")
174
+ FileUtils.expects(:rm_rf).with("/other/path/1234567890")
175
+
176
+ @strategy.deploy!
177
+ end
178
+
179
+ def test_deploy_with_copy_remote_dir_should_copy_to_that_dir
180
+ @config[:copy_remote_dir] = "/somewhere/else"
181
+ Dir.expects(:tmpdir).returns("/temp/dir")
182
+ Dir.expects(:chdir).yields
183
+ @source.expects(:checkout).returns(:local_checkout)
184
+
185
+ @strategy.expects(:system).with(:local_checkout)
186
+ @strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
187
+ @strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/somewhere/else/1234567890.tar.gz")
188
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /somewhere/else/1234567890.tar.gz && rm /somewhere/else/1234567890.tar.gz")
189
+
190
+ mock_file = mock("file")
191
+ mock_file.expects(:puts).with("154")
192
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
193
+
194
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
195
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
196
+
197
+ @strategy.deploy!
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
360
+ end
@@ -0,0 +1,69 @@
1
+ require "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
@@ -0,0 +1,5 @@
1
+ role :test, "www.capistrano.test"
2
+
3
+ task :testing, :roles => :test do
4
+ set :testing_occurred, true
5
+ end
@@ -0,0 +1,5 @@
1
+ set :application, "foo"
2
+ set :repository, "1/2/#{application}"
3
+ set :gateway, "#{__FILE__}.example.com"
4
+
5
+ role :web, "www.example.com", :primary => true
@@ -0,0 +1,3 @@
1
+ ConfigurationLoadingTest::MockConfig.instance(:must_exist).load do
2
+ ping! :custom
3
+ 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