Ensure that resources are always initialized in all cases (#4366)

Ensure that resources are always initialized in all cases
This commit is contained in:
Clinton Wolfe 2019-08-19 12:55:52 -04:00 committed by GitHub
commit 3f54f7ac46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -81,17 +81,13 @@ module Inspec
@resource_skipped = false
@resource_failed = false
@supports = Inspec::Resource.supports[name]
@resource_exception_message = nil
# attach the backend to this instance
@__backend_runner__ = backend
@__resource_name__ = name
# check resource supports
supported = true
supported = check_supports unless @supports.nil?
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
check_supports unless @supports.nil? # this has side effects
# call the resource initializer
begin
@ -100,12 +96,10 @@ module Inspec
skip_resource(e.message)
rescue Inspec::Exceptions::ResourceFailed => e
fail_resource(e.message)
rescue NotImplementedError => e
fail_resource(e.message) unless @resource_failed
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)
skip_resource(e.message) unless @resource_failed
end
end