mirror of
https://github.com/inspec/inspec
synced 2024-11-27 07:00:39 +00:00
Ensure that resources are always initialized in all cases (#4366)
Ensure that resources are always initialized in all cases
This commit is contained in:
commit
3f54f7ac46
1 changed files with 5 additions and 11 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue