-- | -- Module : Test.Amazonka.Error -- Copyright : (c) 2013-2023 Brendan Hay -- License : Mozilla Public License, v. 2.0. -- Maintainer : Brendan Hay -- Stability : provisional -- Portability : non-portable (GHC extensions) module Test.Amazonka.Error (tests) where import Amazonka.Core import Amazonka.Data import Amazonka.Prelude import Network.HTTP.Types.Status (status400, status404) import Test.Amazonka.Arbitrary () import Test.QuickCheck.Property () import Test.Tasty import Test.Tasty.HUnit tests :: TestTree tests = testGroup "errors" [ testGroup "getErrorCode" [ testCase "with header, colon" $ getErrorCode status404 [(hAMZNErrorType, "ResourceNotFoundException")] @?= ErrorCode "ResourceNotFound", testCase "with header, no colon" $ getErrorCode status404 [(hAMZNErrorType, "ResourceNotFoundException:http://iot.amazonaws.com/doc/2015-10-02/")] @?= ErrorCode "ResourceNotFound", testCase "no header" $ getErrorCode status400 [] @?= ErrorCode "Bad Request" ], testGroup "xml" [ testCase "ec2" $ xmlError ec2 "VolumeInUse" "vol-8c8cea98 is already attached to an instance" "c0ca7700-c515-4653-87e3-f1a9ce6416e8", testCase "route53" $ xmlError route53 "InvalidChangeBatch" "Tried to delete resource record set noexist.example.com. type A,but it was not found" "default_rid", testCase "sqs" $ xmlError sqs "InvalidParameterValue" "Value (quename_nonalpha) for parameter QueueName is invalid. Must be an alphanumeric String of 1 to 80 in length" "42d59b56-7407-4c4a-be0f-4c88daeea257" ] ] xmlError :: ByteStringLazy -> ErrorCode -> ErrorMessage -> RequestId -> Assertion xmlError bs c m r = actual @?= Right expect where expect = serviceError a s h (Just c) (Just m) (Just r) actual = case parseXMLError a s h bs of ServiceError e -> Right e e -> Left $ "unexpected error: " ++ show e a = "Test" s = toEnum 400 h = [(hAMZRequestId, "default_rid")] -- Samples representative of differing xml errors. ec2 :: ByteStringLazy ec2 = "VolumeInUsevol-8c8cea98 is already attached to an instancec0ca7700-c515-4653-87e3-f1a9ce6416e8" route53 :: ByteStringLazy route53 = "Tried to delete resource record set noexist.example.com. type A,but it was not found" sqs :: ByteStringLazy sqs = "SenderInvalidParameterValueValue (quename_nonalpha) for parameter QueueName is invalid. Must be an alphanumeric String of 1 to 80 in length42d59b56-7407-4c4a-be0f-4c88daeea257"