forked from capistrano/capistrano
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
4 changed files
with
137 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |