1
0
Fork 0
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:
Berin Larson 2017-07-05 07:32:58 +05:30 committed by Matt Brictson
parent d1d6b5eedc
commit ed0a3f08df
6 changed files with 61 additions and 10 deletions

View file

@ -52,3 +52,12 @@ Feature: Deploy
When I run cap "deploy:symlink:release" When I run cap "deploy:symlink:release"
Then the current directory will be a symlink to the 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

View file

@ -6,7 +6,9 @@ end
Then(/^git wrapper permissions are 0700$/) do Then(/^git wrapper permissions are 0700$/) do
permissions_test = %Q([ $(stat -c "%a" #{TestApp.git_wrapper_path.shellescape}) == "700" ]) 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 end
Then(/^the shared path is created$/) do Then(/^the shared path is created$/) do
@ -124,3 +126,15 @@ end
Then(/doesn't contain "([^"]*)" in the output/) do |expected| Then(/doesn't contain "([^"]*)" in the output/) do |expected|
expect(@output).not_to include(expected) expect(@output).not_to include(expected)
end 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

View file

@ -13,3 +13,9 @@ end
When(/^I run "(.*?)"$/) do |command| When(/^I run "(.*?)"$/) do |command|
@success, @output = TestApp.run(command) @success, @output = TestApp.run(command)
end 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

View file

@ -21,10 +21,16 @@ end
Given(/^file "(.*?)" exists in shared path$/) do |file| Given(/^file "(.*?)" exists in shared path$/) do |file|
file_shared_path = TestApp.shared_path.join(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}") run_vagrant_command("touch #{file_shared_path}")
end 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| Given(/^file "(.*?)" does not exist in shared path$/) do |file|
file_shared_path = TestApp.shared_path.join(file) file_shared_path = TestApp.shared_path.join(file)
run_vagrant_command("mkdir -p #{TestApp.shared_path}") run_vagrant_command("mkdir -p #{TestApp.shared_path}")
@ -60,3 +66,14 @@ end
Given(/^a stage file named (.+)$/) do |filename| Given(/^a stage file named (.+)$/) do |filename|
TestApp.write_local_stage_file(filename) TestApp.write_local_stage_file(filename)
end 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

View file

@ -15,6 +15,10 @@ module RemoteCommandHelpers
%Q{[ -#{type} "#{path}" ]} %Q{[ -#{type} "#{path}" ]}
end end
def symlinked?(symlink_path, target_path)
"[ #{symlink_path} -ef #{target_path} ]"
end
def safely_remove_file(_path) def safely_remove_file(_path)
run_vagrant_command("rm #{test_file}") run_vagrant_command("rm #{test_file}")
rescue rescue

View file

@ -1,4 +1,4 @@
require "English" require "open3"
module VagrantHelpers module VagrantHelpers
extend self extend self
@ -16,17 +16,18 @@ module VagrantHelpers
def vagrant_cli_command(command) def vagrant_cli_command(command)
puts "[vagrant] #{command}" puts "[vagrant] #{command}"
Dir.chdir(VAGRANT_ROOT) do stdout, stderr, status = Dir.chdir(VAGRANT_ROOT) do
`#{VAGRANT_BIN} #{command} 2>&1`.split("\n").each do |line| Open3.capture3("#{VAGRANT_BIN} #{command}")
puts "[vagrant] #{line}"
end
end end
$CHILD_STATUS
(stdout + stderr).each_line { |line| puts "[vagrant] #{line}" }
[stdout, stderr, status]
end end
def run_vagrant_command(command) def run_vagrant_command(command)
status = vagrant_cli_command("ssh -c #{command.inspect}") stdout, stderr, status = vagrant_cli_command("ssh -c #{command.inspect}")
return true if status.success? return [stdout, stderr] if status.success?
raise VagrantSSHCommandError, status raise VagrantSSHCommandError, status
end end
end end