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 1e35e8a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
9 changes: 8 additions & 1 deletion botocore/waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +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.
if isinstance(expected, bool):
# If expected is boolean and true, accept any error code.
# Else, if expected is boolean and false, check if errors were encountered.
if not expected:
return "Error" not in response
else:
return "Error" in response and "Code" in response["Error"]
return response.get("Error", {}).get("Code", "") == expected

This comment has been minimized.

Copy link
@nateprewitt

nateprewitt Jul 16, 2024

Want to clean up the white space here.

return acceptor_matches


Expand Down
40 changes: 40 additions & 0 deletions tests/unit/test_waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,46 @@ def test_single_waiter_supports_error(self):
self.assertFalse(
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'
Expand Down

0 comments on commit 1e35e8a

Please sign in to comment.