public
Description: Remote multi-server automation tool. This repository is no longer being actively maintained. Please ask on the mailing list to find someone who has a well-maintained fork. Thanks!
Homepage: http://www.capify.org
Clone URL: git://github.com/jamis/capistrano.git
Improved test coverage for copy strategy compression.
DRY'd up the compression type lookups and invalid compression type error 
handling.
Ryan McGeary (author)
Mon May 12 20:36:51 -0700 2008
commit  ebe3d9eecb4724736125845424a2608a6c90e644
tree    c133ff50c91591d2cb23215af543422b13b8c8b4
parent  e3844726613d39659804d9f1a2f3423dd6596106
...
146
147
148
149
 
150
151
152
...
166
167
168
 
 
 
 
 
169
170
171
172
173
174
175
176
177
178
179
180
181
 
 
 
 
 
 
182
183
184
 
185
186
187
 
188
189
190
191
192
193
194
 
195
196
197
198
199
200
201
 
202
203
204
205
206
207
208
 
209
210
211
...
146
147
148
 
149
150
151
152
...
166
167
168
169
170
171
172
173
174
175
 
 
 
 
 
 
 
 
 
 
 
176
177
178
179
180
181
182
183
 
184
185
 
 
186
187
 
 
 
 
 
 
188
189
190
191
192
 
 
 
193
194
 
 
 
 
 
 
195
196
197
198
0
@@ -146,7 +146,7 @@ module Capistrano
0
           # Returns the name of the file that the source code will be
0
           # compressed to.
0
           def filename
0
-            @filename ||= File.join(tmpdir, "#{File.basename(destination)}.#{compression_extension}")
0
+            @filename ||= File.join(tmpdir, "#{File.basename(destination)}.#{compression.extension}")
0
           end
0
 
0
           # The directory to which the copy should be checked out
0
@@ -166,46 +166,33 @@ module Capistrano
0
             @remote_filename ||= File.join(remote_dir, File.basename(filename))
0
           end
0
 
0
+          # A struct for representing the specifics of a compression type.
0
+          # Commands are arrays, where the first element is the utility to be
0
+          # used to perform the compression or decompression.
0
+          Compression = Struct.new(:extension, :compress_command, :decompress_command)
0
+          
0
           # The compression method to use, defaults to :gzip.
0
           def compression
0
-            configuration[:copy_compression] || :gzip
0
-          end
0
-
0
-          # Returns the file extension used for the compression method in
0
-          # question.
0
-          def compression_extension
0
-            case compression
0
-            when :gzip, :gz   then "tar.gz"
0
-            when :bzip2, :bz2 then "tar.bz2"
0
-            when :zip         then "zip"
0
-            else raise ArgumentError, "invalid compression type #{compression.inspect}"
0
+            type = configuration[:copy_compression] || :gzip
0
+            case type
0
+            when :gzip, :gz   then Compression.new("tar.gz",  %w(tar czf), %w(tar xzf))
0
+            when :bzip2, :bz2 then Compression.new("tar.bz2", %w(tar cjf), %w(tar xjf))
0
+            when :zip         then Compression.new("zip",     %w(zip -qr), %w(unzip -q))
0
+            else raise ArgumentError, "invalid compression type #{type.inspect}"
0
             end
0
           end
0
-
0
+          
0
           # Returns the command necessary to compress the given directory
0
-          # into the given file. The command is returned as an array, where
0
-          # the first element is the utility to be used to perform the compression.
0
+          # into the given file.
0
           def compress(directory, file)
0
-            case compression
0
-            when :gzip, :gz   then ["tar", "czf", file, directory]
0
-            when :bzip2, :bz2 then ["tar", "cjf", file, directory]
0
-            when :zip         then ["zip", "-qr", file, directory]
0
-            else raise ArgumentError, "invalid compression type #{compression.inspect}"
0
-            end
0
+            compression.compress_command + [file, directory]
0
           end
0
 
0
           # Returns the command necessary to decompress the given file,
0
           # relative to the current working directory. It must also
0
-          # preserve the directory structure in the file. The command is returned
0
-          # as an array, where the first element is the utility to be used to
0
-          # perform the decompression.
0
+          # preserve the directory structure in the file.
0
           def decompress(file)
0
-            case compression
0
-            when :gzip, :gz   then ["tar", "xzf", file]
0
-            when :bzip2, :bz2 then ["tar", "xjf", file]
0
-            when :zip         then ["unzip", "-q", file]
0
-            else raise ArgumentError, "invalid compression type #{compression.inspect}"
0
-            end
0
+            compression.decompress_command + [file]
0
           end
0
       end
0
 
...
86
87
88
89
 
 
 
 
 
 
 
 
 
 
 
90
91
92
...
86
87
88
 
89
90
91
92
93
94
95
96
97
98
99
100
101
102
0
@@ -86,7 +86,17 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
0
 
0
     @strategy.deploy!
0
   end
0
-
0
+  
0
+  def test_deploy_with_unknown_compression_should_error_on_extension
0
+    @config[:copy_compression] = :bogus
0
+    Dir.expects(:tmpdir).returns("/temp/dir")
0
+    @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
0
+    @strategy.stubs(:system)
0
+    File.stubs(:open)
0
+    
0
+    assert_raises(ArgumentError) { @strategy.deploy! }
0
+  end
0
+  
0
   def test_deploy_with_custom_copy_dir_should_use_that_as_tmpdir
0
     Dir.expects(:tmpdir).never
0
     Dir.expects(:chdir).with("/other/path").yields

Comments