Skip to content

Commit

Permalink
fix: Throw SFTP::Error when Bash process started by Shell fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ssciolla authored and niquerio committed Mar 27, 2024
1 parent 0bc446f commit 160ab73
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/sftp/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module SFTP
module Shell
def self.run(array_of_commands)
command_str = [array_of_commands].join(" ")
`bash -c \"#{command_str}\"`
output = `bash -c \"#{command_str}\"`
unless $CHILD_STATUS.success?
raise Error, "Error occurred during SFTP process: #{$CHILD_STATUS.exitstatus}"
end
output
end
end
end
16 changes: 16 additions & 0 deletions spec/sftp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,19 @@
end
end
end

RSpec.describe SFTP::Shell do
before(:each) do
@shell = SFTP::Shell
end

context "#run" do
it "throws Error when run fails" do
expect { @shell.run ["gobbledegook"] }.to raise_error(SFTP::Error)
end

it "returns the output from the command" do
expect(@shell.run(["ls"]).class.to_s).to eq("String")
end
end
end

0 comments on commit 160ab73

Please sign in to comment.