2022-02-08 21:12:51 +00:00
|
|
|
import boto3
|
|
|
|
import pytest
|
|
|
|
from botocore.exceptions import ClientError
|
2023-11-30 15:55:51 +00:00
|
|
|
|
2022-02-08 21:12:51 +00:00
|
|
|
from moto import mock_apigateway
|
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_get_vpc_links_empty():
|
|
|
|
client = boto3.client("apigateway", region_name="eu-west-1")
|
|
|
|
|
|
|
|
resp = client.get_vpc_links()
|
2023-06-07 09:46:18 +00:00
|
|
|
assert resp["items"] == []
|
2022-02-08 21:12:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_create_vpc_link():
|
|
|
|
client = boto3.client("apigateway", region_name="eu-west-1")
|
|
|
|
|
|
|
|
resp = client.create_vpc_link(
|
|
|
|
name="vpcl",
|
|
|
|
description="my first vpc link",
|
|
|
|
targetArns=["elb:target:arn"],
|
|
|
|
tags={"key1": "value1"},
|
|
|
|
)
|
|
|
|
|
2023-06-07 09:46:18 +00:00
|
|
|
assert "id" in resp
|
|
|
|
assert resp["name"] == "vpcl"
|
|
|
|
assert resp["description"] == "my first vpc link"
|
|
|
|
assert resp["targetArns"] == ["elb:target:arn"]
|
|
|
|
assert resp["status"] == "AVAILABLE"
|
|
|
|
assert resp["tags"] == {"key1": "value1"}
|
2022-02-08 21:12:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_get_vpc_link():
|
|
|
|
client = boto3.client("apigateway", region_name="eu-west-1")
|
|
|
|
|
|
|
|
vpc_link_id = client.create_vpc_link(
|
|
|
|
name="vpcl",
|
|
|
|
description="my first vpc link",
|
|
|
|
targetArns=["elb:target:arn"],
|
|
|
|
tags={"key1": "value1"},
|
|
|
|
)["id"]
|
|
|
|
|
|
|
|
resp = client.get_vpc_link(vpcLinkId=vpc_link_id)
|
|
|
|
|
2023-06-07 09:46:18 +00:00
|
|
|
assert "id" in resp
|
|
|
|
assert resp["name"] == "vpcl"
|
|
|
|
assert resp["description"] == "my first vpc link"
|
|
|
|
assert resp["targetArns"] == ["elb:target:arn"]
|
|
|
|
assert resp["status"] == "AVAILABLE"
|
|
|
|
assert resp["tags"] == {"key1": "value1"}
|
2022-02-08 21:12:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_get_vpc_link_unknown():
|
|
|
|
client = boto3.client("apigateway", region_name="ap-southeast-1")
|
|
|
|
|
|
|
|
with pytest.raises(ClientError) as exc:
|
|
|
|
client.get_vpc_link(vpcLinkId="unknown")
|
|
|
|
err = exc.value.response["Error"]
|
2023-06-07 09:46:18 +00:00
|
|
|
assert err["Code"] == "NotFoundException"
|
|
|
|
assert err["Message"] == "VPCLink not found"
|
2022-02-08 21:12:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_get_vpc_links():
|
|
|
|
client = boto3.client("apigateway", region_name="eu-west-1")
|
|
|
|
|
|
|
|
vpc_link_id = client.create_vpc_link(
|
|
|
|
name="vpcl",
|
|
|
|
description="my first vpc link",
|
|
|
|
targetArns=["elb:target:arn"],
|
|
|
|
tags={"key1": "value1"},
|
|
|
|
)["id"]
|
|
|
|
|
|
|
|
links = client.get_vpc_links()["items"]
|
2023-06-07 09:46:18 +00:00
|
|
|
assert len(links) == 1
|
|
|
|
assert links[0]["id"] == vpc_link_id
|
2022-02-08 21:12:51 +00:00
|
|
|
|
|
|
|
client.create_vpc_link(
|
|
|
|
name="vpcl2",
|
|
|
|
description="my first vpc link",
|
|
|
|
targetArns=["elb:target:arn"],
|
|
|
|
tags={"key2": "value2"},
|
|
|
|
)
|
|
|
|
|
|
|
|
links = client.get_vpc_links()["items"]
|
2023-06-07 09:46:18 +00:00
|
|
|
assert len(links) == 2
|
2022-02-08 21:12:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_delete_vpc_link():
|
|
|
|
client = boto3.client("apigateway", region_name="eu-north-1")
|
|
|
|
|
|
|
|
vpc_link_id = client.create_vpc_link(
|
|
|
|
name="vpcl",
|
|
|
|
description="my first vpc link",
|
|
|
|
targetArns=["elb:target:arn"],
|
|
|
|
tags={"key1": "value1"},
|
|
|
|
)["id"]
|
|
|
|
|
|
|
|
links = client.get_vpc_links()["items"]
|
2023-06-07 09:46:18 +00:00
|
|
|
assert len(links) == 1
|
2022-02-08 21:12:51 +00:00
|
|
|
|
|
|
|
client.delete_vpc_link(vpcLinkId=vpc_link_id)
|
|
|
|
|
|
|
|
links = client.get_vpc_links()["items"]
|
2023-06-07 09:46:18 +00:00
|
|
|
assert len(links) == 0
|