Skip to content

Commit

Permalink
Merge pull request #196 from bitglue/fix_commanderror_handling
Browse files Browse the repository at this point in the history
Fix error in error handling when puppet is not installed
  • Loading branch information
carlossg committed Apr 8, 2014
2 parents dc0a84a + 3e1fe89 commit 68e5ce9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/librarian/puppet.rb
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
14 changes: 14 additions & 0 deletions spec/librarian_puppet_spec.rb
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

0 comments on commit 68e5ce9

Please sign in to comment.