-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from bitglue/fix_commanderror_handling
Fix error in error handling when puppet is not installed
- Loading branch information
Showing
2 changed files
with
31 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
require 'librarian' | ||
require 'fileutils' | ||
|
||
out = nil | ||
begin | ||
out = Librarian::Posix.run!(%W{puppet --version}) | ||
rescue Librarian::Posix::CommandFailure => error | ||
|
||
$stderr.puts <<-EOF | ||
Unable to load puppet. Please install it using native packages for your platform (eg .deb, .rpm, .dmg, etc). | ||
puppet --version returned #{status.exitstatus} | ||
#{error.message unless error.message.nil?} | ||
EOF | ||
exit 1 | ||
end | ||
|
||
PUPPET_VERSION=out.split(' ').first.strip | ||
|
||
require 'librarian/puppet/extension' | ||
require 'librarian/puppet/version' | ||
|
||
require 'librarian/action/install' | ||
|
||
module Librarian | ||
module Puppet | ||
def puppet_version | ||
out = nil | ||
begin | ||
out = Librarian::Posix.run!(%W{puppet --version}) | ||
rescue Librarian::Posix::CommandFailure => error | ||
|
||
$stderr.puts <<-EOF | ||
Unable to load puppet. Please install it using native packages for your platform (eg .deb, .rpm, .dmg, etc). | ||
puppet --version returned #{error.status} | ||
#{error.message unless error.message.nil?} | ||
EOF | ||
exit 1 | ||
end | ||
out.split(' ').first.strip | ||
end | ||
end | ||
end | ||
|
||
PUPPET_VERSION=Librarian::Puppet::puppet_version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
describe Librarian::Puppet do | ||
it 'exits with error if puppet is not installed' do | ||
error = Librarian::Posix::CommandFailure.new 'puppet not installed' | ||
error.status = 42 | ||
|
||
expect(Librarian::Posix).to receive(:run!).and_raise(error) | ||
expect($stderr).to receive(:puts) do |message| | ||
expect(message).to match /42/ | ||
expect(message).to match /puppet not installed/ | ||
end | ||
|
||
expect { Librarian::Puppet::puppet_version }.to raise_error(SystemExit) | ||
end | ||
end |