mirror of
https://github.com/inspec/inspec
synced 2024-09-21 06:51:56 +00:00
Capture ArgumentErrors from aws. (#2673)
Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
parent
310fe5009f
commit
2a8bd673b1
2 changed files with 43 additions and 0 deletions
|
@ -6,6 +6,10 @@ module AwsResourceMixin
|
|||
catch_aws_errors do
|
||||
fetch_from_api
|
||||
end
|
||||
rescue ArgumentError => e
|
||||
# continue with ArgumentError if testing
|
||||
raise unless respond_to?(:inspec)
|
||||
raise Inspec::Exceptions::ResourceFailed, e.message
|
||||
end
|
||||
|
||||
# Default implementation of validate params accepts everything.
|
||||
|
|
39
test/unit/resource_supports/aws/aws_resource_mixin_test.rb
Normal file
39
test/unit/resource_supports/aws/aws_resource_mixin_test.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
# encoding: utf-8
|
||||
# copyright: 2017, Chef Software Inc.
|
||||
|
||||
require 'helper'
|
||||
|
||||
describe 'AwsResourceMixin' do
|
||||
describe 'initialize' do
|
||||
class AwsResourceMixinError
|
||||
include AwsResourceMixin
|
||||
def validate_params(_resource_params)
|
||||
raise ArgumentError, 'this param is not right'
|
||||
end
|
||||
end
|
||||
|
||||
it 'confirm ArgumentError is raised when testing' do
|
||||
proc {
|
||||
mixin = AwsResourceMixinError.new({})
|
||||
}.must_raise ArgumentError
|
||||
end
|
||||
|
||||
class AwsResourceMixinLive
|
||||
include AwsResourceMixin
|
||||
def validate_params(_resource_params)
|
||||
raise ArgumentError, 'this param is not right'
|
||||
end
|
||||
|
||||
# if inspec is defined we are a live test
|
||||
def inspec
|
||||
# live
|
||||
end
|
||||
end
|
||||
|
||||
it 'confirm ResourceFailed is raised when live' do
|
||||
proc {
|
||||
mixin = AwsResourceMixinLive.new({})
|
||||
}.must_raise Inspec::Exceptions::ResourceFailed
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue