mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Adds acceptance test for rollback feature. (#1891)
* #1736 Adds acceptance test for rollback feature. * Made vagrant_cli_command function return values explicitly over setting instance variables.
This commit is contained in:
parent
d1d6b5eedc
commit
ed0a3f08df
6 changed files with 61 additions and 10 deletions
|
@ -52,3 +52,12 @@ Feature: Deploy
|
|||
When I run cap "deploy:symlink:release"
|
||||
Then the current directory will be a symlink to the release
|
||||
|
||||
Scenario: Rolling Back
|
||||
Given I make 2 deployments
|
||||
When I run cap "deploy:rollback"
|
||||
Then the current symlink points to the previous release
|
||||
|
||||
Scenario: Rolling Back to a specific release
|
||||
Given I make 3 deployments
|
||||
When I rollback to a specific release
|
||||
Then the current symlink points to that specific release
|
||||
|
|
|
@ -6,7 +6,9 @@ end
|
|||
|
||||
Then(/^git wrapper permissions are 0700$/) do
|
||||
permissions_test = %Q([ $(stat -c "%a" #{TestApp.git_wrapper_path.shellescape}) == "700" ])
|
||||
expect(vagrant_cli_command("ssh -c #{permissions_test.shellescape}")).to be_success
|
||||
_stdout, _stderr, status = vagrant_cli_command("ssh -c #{permissions_test.shellescape}")
|
||||
|
||||
expect(status).to be_success
|
||||
end
|
||||
|
||||
Then(/^the shared path is created$/) do
|
||||
|
@ -124,3 +126,15 @@ end
|
|||
Then(/doesn't contain "([^"]*)" in the output/) do |expected|
|
||||
expect(@output).not_to include(expected)
|
||||
end
|
||||
|
||||
Then(/the current symlink points to the previous release/) do
|
||||
previous_release_path = @release_paths[-2]
|
||||
|
||||
run_vagrant_command(symlinked?(TestApp.current_path, previous_release_path))
|
||||
end
|
||||
|
||||
Then(/^the current symlink points to that specific release$/) do
|
||||
specific_release_path = TestApp.releases_path.join(@rollback_release)
|
||||
|
||||
run_vagrant_command(symlinked?(TestApp.current_path, specific_release_path))
|
||||
end
|
||||
|
|
|
@ -13,3 +13,9 @@ end
|
|||
When(/^I run "(.*?)"$/) do |command|
|
||||
@success, @output = TestApp.run(command)
|
||||
end
|
||||
|
||||
When(/^I rollback to a specific release$/) do
|
||||
@rollback_release = @release_paths.first.split("/").last
|
||||
|
||||
step %Q{I run cap "deploy:rollback ROLLBACK_RELEASE=#{@rollback_release}"}
|
||||
end
|
||||
|
|
|
@ -21,10 +21,16 @@ end
|
|||
|
||||
Given(/^file "(.*?)" exists in shared path$/) do |file|
|
||||
file_shared_path = TestApp.shared_path.join(file)
|
||||
run_vagrant_command("mkdir -p #{TestApp.shared_path}")
|
||||
run_vagrant_command("mkdir -p #{file_shared_path.dirname}")
|
||||
run_vagrant_command("touch #{file_shared_path}")
|
||||
end
|
||||
|
||||
Given(/^all linked files exists in shared path$/) do
|
||||
TestApp.linked_files.each do |linked_file|
|
||||
step %Q{file "#{linked_file}" exists in shared path}
|
||||
end
|
||||
end
|
||||
|
||||
Given(/^file "(.*?)" does not exist in shared path$/) do |file|
|
||||
file_shared_path = TestApp.shared_path.join(file)
|
||||
run_vagrant_command("mkdir -p #{TestApp.shared_path}")
|
||||
|
@ -60,3 +66,14 @@ end
|
|||
Given(/^a stage file named (.+)$/) do |filename|
|
||||
TestApp.write_local_stage_file(filename)
|
||||
end
|
||||
|
||||
Given(/^I make (\d+) deployments$/) do |count|
|
||||
step "all linked files exists in shared path"
|
||||
|
||||
@release_paths = (1..count.to_i).map do
|
||||
TestApp.cap("deploy")
|
||||
stdout, _stderr = run_vagrant_command("readlink #{TestApp.current_path}")
|
||||
|
||||
stdout.strip
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,6 +15,10 @@ module RemoteCommandHelpers
|
|||
%Q{[ -#{type} "#{path}" ]}
|
||||
end
|
||||
|
||||
def symlinked?(symlink_path, target_path)
|
||||
"[ #{symlink_path} -ef #{target_path} ]"
|
||||
end
|
||||
|
||||
def safely_remove_file(_path)
|
||||
run_vagrant_command("rm #{test_file}")
|
||||
rescue
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require "English"
|
||||
require "open3"
|
||||
|
||||
module VagrantHelpers
|
||||
extend self
|
||||
|
@ -16,17 +16,18 @@ module VagrantHelpers
|
|||
|
||||
def vagrant_cli_command(command)
|
||||
puts "[vagrant] #{command}"
|
||||
Dir.chdir(VAGRANT_ROOT) do
|
||||
`#{VAGRANT_BIN} #{command} 2>&1`.split("\n").each do |line|
|
||||
puts "[vagrant] #{line}"
|
||||
end
|
||||
stdout, stderr, status = Dir.chdir(VAGRANT_ROOT) do
|
||||
Open3.capture3("#{VAGRANT_BIN} #{command}")
|
||||
end
|
||||
$CHILD_STATUS
|
||||
|
||||
(stdout + stderr).each_line { |line| puts "[vagrant] #{line}" }
|
||||
|
||||
[stdout, stderr, status]
|
||||
end
|
||||
|
||||
def run_vagrant_command(command)
|
||||
status = vagrant_cli_command("ssh -c #{command.inspect}")
|
||||
return true if status.success?
|
||||
stdout, stderr, status = vagrant_cli_command("ssh -c #{command.inspect}")
|
||||
return [stdout, stderr] if status.success?
|
||||
raise VagrantSSHCommandError, status
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue