Skip to content

Commit

Permalink
Handle expected boolean values for waiter error matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan343 committed Jul 16, 2024
1 parent 786396c commit 16eb865
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
10 changes: 9 additions & 1 deletion botocore/waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,15 @@ def acceptor_matches(response):
# response. So response is still a dictionary, and in the case
# of an error response will contain the "Error" and
# "ResponseMetadata" key.
return response.get("Error", {}).get("Code", "") == expected
# When expected is True, accept any error code.
# When expected is False, check if any errors were encountered.
# Otherwise, check for a specific AWS error code.
if expected is True:
return "Error" in response and "Code" in response["Error"]
elif expected is False:
return "Error" not in response
else:
return response.get("Error", {}).get("Code", "") == expected

return acceptor_matches

Expand Down
32 changes: 32 additions & 0 deletions tests/unit/test_waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,38 @@ def test_single_waiter_supports_error(self):
success_acceptor({'Error': {'Code': 'DoesNotExistErorr'}})
)

def test_single_waiter_supports_no_error(self):
single_waiter = {
'acceptors': [
{
'state': 'success',
'matcher': 'error',
'expected': False,
}
],
}
single_waiter.update(self.boiler_plate_config)
config = SingleWaiterConfig(single_waiter)
success_acceptor = config.acceptors[0].matcher_func
self.assertTrue(success_acceptor({}))
self.assertFalse(success_acceptor({'Error': {'Code': 'ExampleError'}}))

def test_single_waiter_supports_any_error(self):
single_waiter = {
'acceptors': [
{
'state': 'success',
'matcher': 'error',
'expected': True,
}
],
}
single_waiter.update(self.boiler_plate_config)
config = SingleWaiterConfig(single_waiter)
success_acceptor = config.acceptors[0].matcher_func
self.assertTrue(success_acceptor({'Error': {'Code': 'ExampleError1'}}))
self.assertTrue(success_acceptor({'Error': {'Code': 'ExampleError2'}}))

def test_unknown_matcher(self):
unknown_type = 'arbitrary_type'
single_waiter = {
Expand Down

0 comments on commit 16eb865

Please sign in to comment.