-
Notifications
You must be signed in to change notification settings - Fork 53
Refactor e2e tests to use assertion helper class #41
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
df53a64
add Ec2Validator test helper
brycahta 987bbc3
refactor e2e tests to use Ec2Validator helper
brycahta 92a675a
use proper casing for ec2 initialism
brycahta 8dc582b
use default_cidr var in route_table test
brycahta 8b9a842
migrate tgw test logic correctly
brycahta 7be0423
Merge branch 'main' into ref-tests
brycahta dfa4574
Update test_vpc.py
brycahta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
# not use this file except in compliance with the License. A copy of the | ||
# License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
"""Helper functions for ec2 tests | ||
""" | ||
|
||
class EC2Validator: | ||
def __init__(self, ec2_client): | ||
self.ec2_client = ec2_client | ||
|
||
def assert_dhcp_options(self, dhcp_options_id: str, exists=True): | ||
res_found = False | ||
try: | ||
aws_res = self.ec2_client.describe_dhcp_options(DhcpOptionsIds=[dhcp_options_id]) | ||
res_found = len(aws_res["DhcpOptions"]) > 0 | ||
except self.ec2_client.exceptions.ClientError: | ||
pass | ||
assert res_found is exists | ||
|
||
def assert_internet_gateway(self, ig_id: str, exists=True): | ||
res_found = False | ||
try: | ||
aws_res = self.ec2_client.describe_internet_gateways(InternetGatewayIds=[ig_id]) | ||
res_found = len(aws_res["InternetGateways"]) > 0 | ||
except self.ec2_client.exceptions.ClientError: | ||
pass | ||
assert res_found is exists | ||
|
||
def assert_route(self, route_table_id: str, gateway_id: str, origin: str, exists=True): | ||
res_found = False | ||
try: | ||
aws_res = self.ec2_client.describe_route_tables(RouteTableIds=[route_table_id]) | ||
routes = aws_res["RouteTables"][0]["Routes"] | ||
for route in routes: | ||
if route["Origin"] == origin and route["GatewayId"] == gateway_id: | ||
res_found = True | ||
except self.ec2_client.exceptions.ClientError: | ||
pass | ||
assert res_found is exists | ||
|
||
def assert_route_table(self, route_table_id: str, exists=True): | ||
res_found = False | ||
try: | ||
aws_res = self.ec2_client.describe_route_tables(RouteTableIds=[route_table_id]) | ||
res_found = len(aws_res["RouteTables"]) > 0 | ||
except self.ec2_client.exceptions.ClientError: | ||
pass | ||
assert res_found is exists | ||
|
||
def assert_security_group(self, sg_id: str, exists=True): | ||
res_found = False | ||
try: | ||
aws_res = self.ec2_client.describe_security_groups(GroupIds=[sg_id]) | ||
res_found = len(aws_res["SecurityGroups"]) > 0 | ||
except self.ec2_client.exceptions.ClientError: | ||
pass | ||
assert res_found is exists | ||
|
||
def assert_subnet(self, subnet_id: str, exists=True): | ||
res_found = False | ||
try: | ||
aws_res = self.ec2_client.describe_subnets(SubnetIds=[subnet_id]) | ||
res_found = len(aws_res["Subnets"]) > 0 | ||
except self.ec2_client.exceptions.ClientError: | ||
pass | ||
assert res_found is exists | ||
|
||
def assert_transit_gateway(self, tgw_id: str, exists=True): | ||
res_found = False | ||
try: | ||
aws_res = self.ec2_client.describe_transit_gateways(TransitGatewayIds=[tgw_id]) | ||
tgw = aws_res["TransitGateways"][0] | ||
# TransitGateway may take awhile to be removed server-side, so | ||
# treat 'deleting' and 'deleted' states as resource no longer existing | ||
res_found = tgw is not None and tgw['State'] != "deleting" and tgw['State'] != "deleted" | ||
except self.ec2_client.exceptions.ClientError: | ||
pass | ||
assert res_found is exists | ||
|
||
def assert_vpc(self, vpc_id: str, exists=True): | ||
res_found = False | ||
try: | ||
aws_res = self.ec2_client.describe_vpcs(VpcIds=[vpc_id]) | ||
res_found = len(aws_res["Vpcs"]) > 0 | ||
except self.ec2_client.exceptions.ClientError: | ||
pass | ||
assert res_found is exists | ||
|
||
def assert_vpc_endpoint(self, vpc_endpoint_id: str, exists=True): | ||
res_found = False | ||
try: | ||
aws_res = self.ec2_client.describe_vpc_endpoints(VpcEndpointIds=[vpc_endpoint_id]) | ||
res_found = len(aws_res["VpcEndpoints"]) > 0 | ||
except self.ec2_client.exceptions.ClientError: | ||
pass | ||
assert res_found is exists |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.