From 0ab4ae7d6ea9b62891c79a57544de830b57d2641 Mon Sep 17 00:00:00 2001 From: Chris Redekop Date: Fri, 28 Apr 2017 10:40:19 +0000 Subject: [PATCH] Update resource based on PR feedback Signed-off-by: Chris Redekop --- libraries/aws_iam_access_key.rb | 4 +--- .../unit/resources/aws_iam_access_key_test.rb | 22 +++++++++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/libraries/aws_iam_access_key.rb b/libraries/aws_iam_access_key.rb index 8e4846487..199876399 100644 --- a/libraries/aws_iam_access_key.rb +++ b/libraries/aws_iam_access_key.rb @@ -18,9 +18,7 @@ class AwsIamAccessKey < Inspec.resource(1) def exists? !access_key.nil? - rescue AccessKeyNotFoundError - false - rescue Aws::IAM::Errors::NoSuchEntity + rescue AccessKeyNotFoundError, Aws::IAM::Errors::NoSuchEntity false end diff --git a/test/unit/resources/aws_iam_access_key_test.rb b/test/unit/resources/aws_iam_access_key_test.rb index 044ba18fe..e4be92c66 100644 --- a/test/unit/resources/aws_iam_access_key_test.rb +++ b/test/unit/resources/aws_iam_access_key_test.rb @@ -85,31 +85,29 @@ class AwsIamAccessKeyTest < Minitest::Test def test_get_access_key_raises_when_no_access_keys_found validator = mock_validator - begin + e = assert_raises AwsIamAccessKey::AccessKeyNotFoundError do iam_client_decorator(validator).get_access_key(Username, Id) - flunk - rescue AwsIamAccessKey::AccessKeyNotFoundError => e - assert_match(/.*access key not found.*/, e.message) - assert_match(/.*#{Username}.*/, e.message) - assert_match(/.*#{Id}.*/, e.message) end + assert_match(/.*access key not found.*/, e.message) + assert_match(/.*#{Username}.*/, e.message) + assert_match(/.*#{Id}.*/, e.message) + validator.verify end def test_get_access_key_raises_when_matching_access_key_not_found validator = mock_validator - begin + e = assert_raises AwsIamAccessKey::AccessKeyNotFoundError do iam_client_decorator(validator, [stub_access_key(id: 'Foo')]) .get_access_key(Username, Id) - flunk - rescue AwsIamAccessKey::AccessKeyNotFoundError => e - assert_match(/.*access key not found.*/, e.message) - assert_match(/.*#{Username}.*/, e.message) - assert_match(/.*#{Id}.*/, e.message) end + assert_match(/.*access key not found.*/, e.message) + assert_match(/.*#{Username}.*/, e.message) + assert_match(/.*#{Id}.*/, e.message) + validator.verify end