diff --git a/features/deploy.feature b/features/deploy.feature index 36e29051..5f585fec 100644 --- a/features/deploy.feature +++ b/features/deploy.feature @@ -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 diff --git a/features/step_definitions/assertions.rb b/features/step_definitions/assertions.rb index 6926407c..0ff483af 100644 --- a/features/step_definitions/assertions.rb +++ b/features/step_definitions/assertions.rb @@ -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 diff --git a/features/step_definitions/cap_commands.rb b/features/step_definitions/cap_commands.rb index c72d9f4a..57b0000d 100644 --- a/features/step_definitions/cap_commands.rb +++ b/features/step_definitions/cap_commands.rb @@ -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 diff --git a/features/step_definitions/setup.rb b/features/step_definitions/setup.rb index 69b2b9a6..dcf21dc7 100644 --- a/features/step_definitions/setup.rb +++ b/features/step_definitions/setup.rb @@ -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 diff --git a/features/support/remote_command_helpers.rb b/features/support/remote_command_helpers.rb index 91420c1f..784dd2c8 100644 --- a/features/support/remote_command_helpers.rb +++ b/features/support/remote_command_helpers.rb @@ -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 diff --git a/features/support/vagrant_helpers.rb b/features/support/vagrant_helpers.rb index 1dbdf874..a0465a2a 100644 --- a/features/support/vagrant_helpers.rb +++ b/features/support/vagrant_helpers.rb @@ -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