Capture ArgumentErrors from aws. (#2673)

Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
Jared Quick 2018-02-17 10:50:35 -05:00 committed by Christoph Hartmann
parent 310fe5009f
commit 2a8bd673b1
2 changed files with 43 additions and 0 deletions

View file

@ -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.

View 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