2017-06-19 15:07:36 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
|
|
|
|
|
|
|
require 'helper'
|
|
|
|
require 'inspec/resource'
|
|
|
|
|
|
|
|
describe Inspec::Resources::Cmd do
|
|
|
|
let(:x) { rand.to_s }
|
|
|
|
def resource(y)
|
|
|
|
load_resource('command', y)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'prints as a bash command' do
|
|
|
|
resource(x).to_s.must_equal 'Command '+x
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'runs a valid mocked command' do
|
|
|
|
resource('env').result.wont_be_nil
|
|
|
|
resource('env').stdout.must_equal "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\n"
|
|
|
|
resource('env').stderr.must_equal ''
|
|
|
|
resource('env').exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
|
2017-12-05 13:21:31 +00:00
|
|
|
it 'exist? returns false on nil os name' do
|
|
|
|
Inspec::Resources::OSResource.any_instance.stubs(:name).returns(nil)
|
|
|
|
resource('test').exist?.must_equal false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exist? returns false on mock os name' do
|
|
|
|
Inspec::Resources::OSResource.any_instance.stubs(:name).returns('mock')
|
|
|
|
resource('test').exist?.must_equal false
|
|
|
|
end
|
|
|
|
|
2017-06-19 15:07:36 +00:00
|
|
|
it 'raises when called with nil as a command' do
|
|
|
|
proc { resource(nil).result }.must_raise StandardError
|
|
|
|
end
|
|
|
|
end
|