Skip to content

Commit

Permalink
Merge pull request #505 from welaika/hooks_exceptions
Browse files Browse the repository at this point in the history
Hooks exceptions
  • Loading branch information
alessandro-fazzi authored Jan 6, 2019
2 parents dd2d950 + 8b854ec commit 9b3dd0a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/wordmove/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ class MovefileNotFound < StandardError; end
class ShellCommandError < StandardError; end
class ImplementInSubclassError < StandardError; end
class UnmetPeerDependencyError < StandardError; end
class RemoteHookException < StandardError; end
class LocalHookException < StandardError; end
end
4 changes: 3 additions & 1 deletion lib/wordmove/hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.run(action, step, cli_options)

if options[environment][:ftp]
logger.debug "You have configured remote hooks to run over "\
"an FTP connections, but this is not possible. Skipping."
"an FTP connection, but this is not possible. Skipping."

return
end
Expand Down Expand Up @@ -82,6 +82,7 @@ def self.run(commands, options, simulate = false)
logger.success ""
else
logger.error "Error code: #{$CHILD_STATUS.exitstatus}"
raise Wordmove::LocalHookException
end
end
end
Expand Down Expand Up @@ -112,6 +113,7 @@ def self.run(commands, options, simulate = false)
else
logger.task_step false, "Output: #{stderr}"
logger.error "Error code #{exit_code}"
raise Wordmove::RemoteHookException
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/fixtures/movefiles/with_hooks
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,23 @@ ssh_with_hooks_partially_filled:
after:
local:
- echo "I've partially configured my hooks"

ssh_with_hooks_which_return_error:
vhost: "http://staging.mysite.example.com"
wordpress_path: "/var/www/your_site" # use an absolute path here

database:
name: "database_name"
user: "user"
password: "password"
host: "host"

ssh:
host: "staging.mysite.example.com"
user: "user"

hooks:
push:
after:
local:
- 'exit 127'
32 changes: 28 additions & 4 deletions spec/hook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@
.to_stdout_from_any_process
end
end

context "with local hook errored" do
let(:options) { common_options.merge("environment" => 'ssh_with_hooks_which_return_error') }

it "logs an error and raises a LocalHookException" do
expect do
expect do
cli.invoke(:push, [], options)
end.to raise_exception(Wordmove::LocalHookException)
end.to output(/Error code: 127/)
.to_stdout_from_any_process
end
end
end

context "when pulling from a remote with ssh" do
Expand Down Expand Up @@ -109,19 +122,30 @@
.to_stdout_from_any_process
end

context "with remote error" do
context "with remote hook errored" do
before do
allow_any_instance_of(Photocopier::SSH)
.to receive(:exec!)
.with(String)
.and_return(['Stubbed remote stdout', 'Stubbed remote stderr', 1])
end

it "returns remote stdout" do
expect { cli.invoke(:pull, [], options) }
.to output(/Stubbed remote stderr/)
it "returns remote stdout and raise an exception" do
expect do
expect do
cli.invoke(:pull, [], options)
end.to raise_exception(Wordmove::RemoteHookException)
end.to output(/Stubbed remote stderr/)
.to_stdout_from_any_process
end

it "raises a RemoteHookException" do
expect do
silence_stream(STDOUT) do
cli.invoke(:pull, [], options)
end
end.to raise_exception(Wordmove::RemoteHookException)
end
end
end

Expand Down

0 comments on commit 9b3dd0a

Please sign in to comment.