Add logic to Puppet status code

This is used in multiple places now, and it should be boxed up with the
Puppet status anyway.
This commit is contained in:
Yossef Mendelssohn
2012-10-10 12:41:50 -04:00
parent 26e2899728
commit bddede55b6
2 changed files with 20 additions and 1 deletions

View File

@@ -6,6 +6,14 @@ module Boxen
# Manages an invocation of puppet.
class Puppeteer
Status = Struct.new(:code) do
# Puppet's detailed exit codes reserves 2 for a successful run with changes
def success?
[0,2].include?(code)
end
end
attr_reader :config
def initialize(config)
@@ -77,7 +85,7 @@ module Boxen
warn command.join " " if config.debug?
Boxen::Util.sudo *command
$?.exitstatus
Status.new($?.exitstatus)
end
end
end

View File

@@ -75,4 +75,15 @@ class BoxenPuppeteerTest < Boxen::Test
assert found, "Flags must include #{flag} #{value}."
end
def test_status
status = Boxen::Puppeteer::Status.new(0)
assert status.success?
status = Boxen::Puppeteer::Status.new(2)
assert status.success?
status = Boxen::Puppeteer::Status.new(1)
refute status.success?
end
end