Fix:Ec2-VPC:Added functionality describe-vpc-endpoint (#3524)

* Fix:Ec2:Added fucntionality describe-vpc-endpoint

* Refactor

* Added test cases for errors
This commit is contained in:
usmangani1 2020-12-08 03:09:57 +05:30 committed by GitHub
commit af60306371
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 154 additions and 3 deletions

View file

@ -8,7 +8,8 @@ from botocore.exceptions import ClientError
import boto3
import boto
from boto.exception import EC2ResponseError
import sure # noqa
# import sure # noqa
from moto import mock_ec2, mock_ec2_deprecated
@ -868,3 +869,50 @@ def test_describe_vpc_end_point_services():
"us-west-1a",
"us-west-1b",
]
@mock_ec2
def test_describe_vpc_end_points():
ec2 = boto3.client("ec2", region_name="us-west-1")
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
route_table = ec2.create_route_table(VpcId=vpc["Vpc"]["VpcId"])
vpc_end_point = ec2.create_vpc_endpoint(
VpcId=vpc["Vpc"]["VpcId"],
ServiceName="com.amazonaws.us-east-1.s3",
RouteTableIds=[route_table["RouteTable"]["RouteTableId"]],
VpcEndpointType="gateway",
)
vpc_endpoints = ec2.describe_vpc_endpoints()
assert vpc_endpoints.get("VpcEndpoints")[0].get(
"VpcEndpointId"
) == vpc_end_point.get("VpcEndpoint").get("VpcEndpointId")
assert vpc_endpoints.get("VpcEndpoints")[0].get("VpcId") == vpc["Vpc"]["VpcId"]
assert vpc_endpoints.get("VpcEndpoints")[0].get("RouteTableIds") == [
route_table.get("RouteTable").get("RouteTableId")
]
assert "VpcEndpointType" in vpc_endpoints.get("VpcEndpoints")[0]
assert "ServiceName" in vpc_endpoints.get("VpcEndpoints")[0]
assert "State" in vpc_endpoints.get("VpcEndpoints")[0]
vpc_endpoints = ec2.describe_vpc_endpoints(
VpcEndpointIds=[vpc_end_point.get("VpcEndpoint").get("VpcEndpointId")]
)
assert vpc_endpoints.get("VpcEndpoints")[0].get(
"VpcEndpointId"
) == vpc_end_point.get("VpcEndpoint").get("VpcEndpointId")
assert vpc_endpoints.get("VpcEndpoints")[0].get("VpcId") == vpc["Vpc"]["VpcId"]
assert vpc_endpoints.get("VpcEndpoints")[0].get("RouteTableIds") == [
route_table.get("RouteTable").get("RouteTableId")
]
assert "VpcEndpointType" in vpc_endpoints.get("VpcEndpoints")[0]
assert "ServiceName" in vpc_endpoints.get("VpcEndpoints")[0]
assert "State" in vpc_endpoints.get("VpcEndpoints")[0]
try:
ec2.describe_vpc_endpoints(
VpcEndpointIds=[route_table.get("RouteTable").get("RouteTableId")]
)
except ClientError as err:
assert err.response["Error"]["Code"] == "InvalidVpcEndPointId.NotFound"