1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Start writing tests for the deployment code. Make the copy strategy checkout 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
This commit is contained in:
Jamis Buck 2007-04-27 02:20:21 +00:00
parent eb6b1effc9
commit c472b3641f
4 changed files with 137 additions and 6 deletions

View file

@ -1,5 +1,10 @@
*SVN* *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] * 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] * 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] * Merged the Configuration and Actor classes, performed various other massive refactorings of the code [Jamis Buck]
*1.4.1* (February 24, 2007) *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] * Use the no-auth-cache option with subversion so that username/password tokens do not get cached by capistrano usage [jonathan]

View file

@ -50,8 +50,8 @@ end
desc "Publish the beta gem" desc "Publish the beta gem"
task :pgem => [:package] do task :pgem => [:package] do
Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload Rake::SshFilePublisher.new("wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
`ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'` `ssh wrath.rubyonrails.org './gemupdate.sh'`
end end
desc "Clean up generated directories and files" desc "Clean up generated directories and files"
@ -59,4 +59,4 @@ task :clean do
rm_rf "pkg" rm_rf "pkg"
rm_rf "doc" rm_rf "doc"
rm_rf "coverage" rm_rf "coverage"
end end

View file

@ -1,5 +1,6 @@
require 'capistrano/recipes/deploy/strategy/base' require 'capistrano/recipes/deploy/strategy/base'
require 'fileutils' require 'fileutils'
require 'tempfile' # Dir.tmpdir
module Capistrano module Capistrano
module Deploy module Deploy
@ -51,7 +52,7 @@ module Capistrano
# Returns the basename of the release_path, which will be used to # Returns the basename of the release_path, which will be used to
# name the local copy and archive file. # name the local copy and archive file.
def destination def destination
@destination ||= File.basename(configuration[:release_path]) @destination ||= File.join(tmpdir, File.basename(configuration[:release_path]))
end end
# Returns the value of the :copy_strategy variable, defaulting to # Returns the value of the :copy_strategy variable, defaulting to
@ -74,13 +75,18 @@ module Capistrano
# Returns the name of the file that the source code will be # Returns the name of the file that the source code will be
# compressed to. # compressed to.
def filename 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 end
# The location on the remote server where the file should be # The location on the remote server where the file should be
# temporarily stored. # temporarily stored.
def remote_filename def remote_filename
@remote_filename ||= "/tmp/#{filename}" @remote_filename ||= "/tmp/#{File.basename(filename)}"
end end
# The compression method to use, defaults to :gzip. # The compression method to use, defaults to :gzip.

View file

@ -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