Permalink
Browse files

Start writing tests for the deployment code. Make the copy strategy c…

…heckout to a customizable tmpdir, instead of merely using cwd

git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6589 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent eb6b1ef commit c472b3641f5b09702b6cc8f8d8f2efdb807cb6e5 @jamis jamis committed Apr 27, 2007
Showing with 137 additions and 6 deletions.
  1. +6 −0 CHANGELOG
  2. +3 −3 Rakefile
  3. +9 −3 lib/capistrano/recipes/deploy/strategy/copy.rb
  4. +119 −0 test/deploy/strategy/copy_test.rb
View
@@ -1,5 +1,10 @@
*SVN*
+* Make the copy strategy check out to a temporary directory [Jamis Buck]
+
+
+*1.99.0 (2.0 Preview 1)* April 24, 2007
+
* Add `capify' script to make it easier to prepare a project for deployment using cap [Jamis Buck]
* Make sure the sudo helper understands the SuSE dialect of the sudo password prompt [Steven Wisener]
@@ -18,6 +23,7 @@
* Merged the Configuration and Actor classes, performed various other massive refactorings of the code [Jamis Buck]
+
*1.4.1* (February 24, 2007)
* Use the no-auth-cache option with subversion so that username/password tokens do not get cached by capistrano usage [jonathan]
View
@@ -50,13 +50,13 @@ end
desc "Publish the beta gem"
task :pgem => [:package] do
- Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
- `ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'`
+ Rake::SshFilePublisher.new("wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
+ `ssh wrath.rubyonrails.org './gemupdate.sh'`
end
desc "Clean up generated directories and files"
task :clean do
rm_rf "pkg"
rm_rf "doc"
rm_rf "coverage"
-end
+end
@@ -1,5 +1,6 @@
require 'capistrano/recipes/deploy/strategy/base'
require 'fileutils'
+require 'tempfile' # Dir.tmpdir
module Capistrano
module Deploy
@@ -51,7 +52,7 @@ def check!
# Returns the basename of the release_path, which will be used to
# name the local copy and archive file.
def destination
- @destination ||= File.basename(configuration[:release_path])
+ @destination ||= File.join(tmpdir, File.basename(configuration[:release_path]))
end
# Returns the value of the :copy_strategy variable, defaulting to
@@ -74,13 +75,18 @@ def command
# Returns the name of the file that the source code will be
# compressed to.
def filename
- @filename ||= "#{destination}.#{compression_extension}"
+ @filename ||= File.join(tmpdir, "#{File.basename(destination)}.#{compression_extension}")
+ end
+
+ # The directory to which the copy should be checked out
+ def tmpdir
+ @tmpdir ||= configuration[:copy_dir] || Dir.tmpdir
end
# The location on the remote server where the file should be
# temporarily stored.
def remote_filename
- @remote_filename ||= "/tmp/#{filename}"
+ @remote_filename ||= "/tmp/#{File.basename(filename)}"
end
# The compression method to use, defaults to :gzip.
@@ -0,0 +1,119 @@
+require "#{File.dirname(__FILE__)}/../../utils"
+require 'capistrano/logger'
+require 'capistrano/recipes/deploy/strategy/copy'
+
+class DeployStrategyCopyTest < Test::Unit::TestCase
+ def setup
+ @config = { :logger => Capistrano::Logger.new(:output => StringIO.new),
+ :releases_path => "/u/apps/test/releases",
+ :release_path => "/u/apps/test/releases/1234567890",
+ :real_revision => "154" }
+ @source = mock("source")
+ @config.stubs(:source).returns(@source)
+ @strategy = Capistrano::Deploy::Strategy::Copy.new(@config)
+ end
+
+ def test_deploy_with_defaults_should_use_tar_gz_and_checkout
+ Dir.expects(:tmpdir).returns("/temp/dir")
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
+
+ @strategy.expects(:system).with(:local_checkout)
+ @strategy.expects(:system).with("tar czf /temp/dir/1234567890.tar.gz /temp/dir/1234567890")
+ @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.gz")
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
+
+ mock_file = mock("file")
+ mock_file.expects(:puts).with("154")
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
+ File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents)
+
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
+
+ @strategy.deploy!
+ end
+
+ def test_deploy_with_export_should_use_tar_gz_and_export
+ Dir.expects(:tmpdir).returns("/temp/dir")
+ @config[:copy_strategy] = :export
+ @source.expects(:export).with("154", "/temp/dir/1234567890").returns(:local_export)
+
+ @strategy.expects(:system).with(:local_export)
+ @strategy.expects(:system).with("tar czf /temp/dir/1234567890.tar.gz /temp/dir/1234567890")
+ @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.gz")
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
+
+ mock_file = mock("file")
+ mock_file.expects(:puts).with("154")
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
+ File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents)
+
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
+
+ @strategy.deploy!
+ end
+
+ def test_deploy_with_zip_should_use_zip_and_checkout
+ Dir.expects(:tmpdir).returns("/temp/dir")
+ @config[:copy_compression] = :zip
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
+
+ @strategy.expects(:system).with(:local_checkout)
+ @strategy.expects(:system).with("zip -qr /temp/dir/1234567890.zip /temp/dir/1234567890")
+ @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.zip")
+ @strategy.expects(:run).with("cd /u/apps/test/releases && unzip -q /tmp/1234567890.zip && rm /tmp/1234567890.zip")
+
+ mock_file = mock("file")
+ mock_file.expects(:puts).with("154")
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
+ File.expects(:read).with("/temp/dir/1234567890.zip").returns(:mock_file_contents)
+
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.zip")
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
+
+ @strategy.deploy!
+ end
+
+ def test_deploy_with_bzip2_should_use_zip_and_checkout
+ Dir.expects(:tmpdir).returns("/temp/dir")
+ @config[:copy_compression] = :bzip2
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
+
+ @strategy.expects(:system).with(:local_checkout)
+ @strategy.expects(:system).with("tar cjf /temp/dir/1234567890.tar.bz2 /temp/dir/1234567890")
+ @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.bz2")
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xjf /tmp/1234567890.tar.bz2 && rm /tmp/1234567890.tar.bz2")
+
+ mock_file = mock("file")
+ mock_file.expects(:puts).with("154")
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
+ File.expects(:read).with("/temp/dir/1234567890.tar.bz2").returns(:mock_file_contents)
+
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.bz2")
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
+
+ @strategy.deploy!
+ end
+
+ def test_deploy_with_custom_copy_dir_should_use_that_as_tmpdir
+ Dir.expects(:tmpdir).never
+ @config[:copy_dir] = "/other/path"
+ @source.expects(:checkout).with("154", "/other/path/1234567890").returns(:local_checkout)
+
+ @strategy.expects(:system).with(:local_checkout)
+ @strategy.expects(:system).with("tar czf /other/path/1234567890.tar.gz /other/path/1234567890")
+ @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.gz")
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
+
+ mock_file = mock("file")
+ mock_file.expects(:puts).with("154")
+ File.expects(:open).with("/other/path/1234567890/REVISION", "w").yields(mock_file)
+ File.expects(:read).with("/other/path/1234567890.tar.gz").returns(:mock_file_contents)
+
+ FileUtils.expects(:rm).with("/other/path/1234567890.tar.gz")
+ FileUtils.expects(:rm_rf).with("/other/path/1234567890")
+
+ @strategy.deploy!
+ end
+end

0 comments on commit c472b36

Please sign in to comment.