reimplement command resource

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-08-28 16:08:24 -07:00
parent e0459c4116
commit 554accdedc
2 changed files with 29 additions and 11 deletions

View file

@ -1,14 +1,32 @@
# encoding: utf-8
# copyright: 2015, Vulcano Security GmbH
# encoding: utf-8
# license: All rights reserved
module Serverspec::Type
class Command < Base
# Check if a given command (executable) exists
# in the default path
def exists?
cmd = @name
Command.new("type \"#{cmd}\" > /dev/null").exit_status == 0
end
class Command < Vulcano.resource(1)
name 'command'
def initialize(cmd)
@command = cmd
end
end
def result
@result ||= @vulcano.run_command(@command)
end
def stdout
result.stdout
end
def stderr
result.stderr
end
def exit_status
result.exit_status.to_i
end
def exists?
res = @vulcano.run_command("type \"#{@command}\" > /dev/null")
res.exit_status.to_i == 0
end
end

View file

@ -40,7 +40,7 @@ module Vulcano::Backend::Mock
end
class Command
attr_reader :stdout, :stderr, :exit_code
attr_reader :stdout, :stderr, :exit_status
def initialize(runtime, cmd)
@exit_code = (rand < 0.7) ? 0 : (100 * rand).to_i
@stdout = (0...50).map { ('a'..'z').to_a[rand(26)] }.join