-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
EventBridge Connections tests plus implementation #11836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
c528d7f
to
4e2faab
Compare
65789a7
to
c87049c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @zaingz with thorough validations and parametrized test coverage 👏 👏 👏
Most comments are improvement suggestions, but I see two things we need to fix:
- Test fixtures miss cleanups when run against AWS. Each fixture should ensure that all created resources are automatically deleted upon test teardown. This is typically achieved by yielding and then cleaning up the created resource and potential dependency. Example:
aws.services.events.conftest.events_put_rule
- Persistence isn't implemented for connections and API destinations because they are not stored in the LS store in
localstack-core/localstack/services/events/models.py
. EventBridge tries to do persistence quite differently than most other services, which requires keeping track of instances at multiple places.
These shouldn't block API functionality, so we can consider merging this PR and tackling these fixes in an immediate follow-up. What do you think?
|
||
def on_before_start(self): | ||
JobScheduler.start() | ||
|
||
def on_before_stop(self): | ||
JobScheduler.shutdown() | ||
|
||
########## | ||
# Helper Methods for connections and api destinations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Organization: We tend to externalize such helper methods into utils.py
as standalone methods (PyCharm also suggests these helpers may be static)
return ListConnectionsResponse(Connections=connections) | ||
|
||
except Exception as e: | ||
raise ValidationException(f"Error listing connections: {str(e)}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to log in to LS logs here?
It would make it easier to debug having a stack trace in the logs.
if limit: | ||
connections = connections[:limit] | ||
|
||
return ListConnectionsResponse(Connections=connections) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the listing supports pagination: https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_ListConnections.html. We could consider adding it in a follow up or upon request.
There should be plenty of examples in LS: https://github.com/localstack/localstack/pulls?q=is%3Apr+is%3Aclosed+paginate
Greg also knows about it :)
|
||
return ListApiDestinationsResponse( | ||
ApiDestinations=api_destination_summaries, | ||
NextToken=None, # Pagination token handling can be added if needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 ok in a follow up or upon request
@@ -740,6 +740,41 @@ def stepfunctions_api(): | |||
# def custom(fn: Callable[[dict], dict]) -> Transformer: | |||
# return GenericTransformer(fn) | |||
|
|||
@staticmethod | |||
def eventbridge_api_destination(snapshot, connection_name: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the other pytest fixture use the botocore name events
as prefix rather than eventbridge, might be a little more discoverable and consistent to standardize
AuthParameters=auth_parameters, | ||
) | ||
|
||
return _create_connection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we missing some cleanup here or does that happen somewhere else?
That's mainly relevant when testing against AWS
|
||
|
||
@pytest.fixture | ||
def create_connection(aws_client, connection_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice usage and extensions of our snapshot utilities 👏
|
||
class TestEventBridgeConnections: | ||
@pytest.fixture | ||
def connection_snapshots(self, snapshot, connection_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hint: if the snapshot fixture is used everywhere, it's possible to use @pytest.fixture(autouse=True)
Example from aws.services.lambda_.test_lambda.fixture_snapshot
@pytest.fixture(autouse=True)
def fixture_snapshot(snapshot):
snapshot.add_transformer(snapshot.transform.lambda_api())
snapshot.add_transformer(
snapshot.transform.key_value("CodeSha256", reference_replacement=False)
)
is_old_provider(), | ||
reason="V1 provider does not support this feature", | ||
) | ||
@pytest.mark.parametrize("auth_params", API_DESTINATION_AUTH_PARAMS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nicely parameterized 👏 👏👏
}, | ||
) | ||
|
||
response = aws_client.events.list_connections(NamePrefix=connection_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well-handled scoping 💯
c87049c
to
1f8b756
Compare
Merging this after a tiny rebase (just an import error) because the pipeline was green and we need this missing feature for testing the default switch in #11834 |
Motivation
Implemented EventBridge Connections and API Destinations in LocalStack to support integration with external APIs and services.
Changes
Connections API:
CreateConnection
,UpdateConnection
,ListConnections
, andDeleteConnection
.BASIC
,API_KEY
, andOAUTH_CLIENT_CREDENTIALS
.SecretArn
.AUTHORIZED
,AUTHORIZING
,DELETING
) with accurate timestamps.API Destinations API:
CreateApiDestination
,UpdateApiDestination
,DescribeApiDestination
,ListApiDestinations
, andDeleteApiDestination
.Testing and Fixtures:
create_connection
,create_api_destination
) for reusable setup in tests.Testing
Connections:
API Destinations:
Snapshot Testing: