Fix inspec check to work with platforms (#2737)

* Fix inspec check to work with platforms.

Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
Jared Quick 2018-02-26 11:01:23 -05:00 committed by GitHub
parent b9d06d7413
commit 20a0b0e025
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View file

@ -43,7 +43,7 @@ module Inspec
Inspec::Resource.registry
end
def __register(name, obj) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def __register(name, obj) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
cl = Class.new(obj) do # rubocop:disable Metrics/BlockLength
attr_reader :resource_exception_message
@ -59,12 +59,9 @@ module Inspec
# check resource supports
supported = true
supported = check_supports unless @supports.nil?
if defined?(Train::Transports::Mock::Connection) && backend.backend.class == Train::Transports::Mock::Connection
# do not exit out for tests
elsif supported == false
# do not run resource initalize if we are unsupported
return
end
test_backend = defined?(Train::Transports::Mock::Connection) && backend.backend.class == Train::Transports::Mock::Connection
# do not return if we are supported, or for tests
return unless supported || test_backend
# call the resource initializer
begin
@ -73,6 +70,11 @@ module Inspec
skip_resource(e.message)
rescue Inspec::Exceptions::ResourceFailed => e
fail_resource(e.message)
rescue NoMethodError => e
# The new platform resources have methods generated on the fly
# for inspec check to work we need to skip these train errors
raise unless test_backend && e.receiver.class == Train::Transports::Mock::Connection
skip_resource(e.message)
end
end

View file

@ -36,4 +36,18 @@ describe 'inspec check' do
out.exit_status.must_equal 0
end
end
describe 'inspec check with a aws profile' do
it 'ignore train connection error' do
out = inspec('check ' + File.join(examples_path, 'profile-aws'))
out.exit_status.must_equal 0
end
end
describe 'inspec check with a azure profile' do
it 'ignore train connection error' do
out = inspec('check ' + File.join(examples_path, 'profile-azure'))
out.exit_status.must_equal 0
end
end
end