Skip to content

Commit 848299d

Browse files
authored
Fix integ tests for feature toggle related to custom domain (#266)
1 parent d262e03 commit 848299d

13 files changed

+111
-10
lines changed

integration/combination/test_custom_http_api_domains_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ def test_custom_http_api_domains_regional(self):
2121
api_gateway_client = self.client_provider.api_v2_client
2222
result = api_gateway_client.get_domain_name(DomainName=domain_name_id)
2323

24-
self.assertEqual("httpapi.sam-gamma-regional.com", result["DomainName"])
24+
if "FeatureToggle" in self.pipeline_prefix:
25+
self.assertEqual("httpapi.ftl.sam-gamma-regional.com", result["DomainName"])
26+
else:
27+
self.assertEqual("httpapi.sam-gamma-regional.com", result["DomainName"])
2528

2629
mtls_auth_config = result["MutualTlsAuthentication"]
2730
self.assertEqual(self.file_to_s3_uri_map["MTLSCert.pem"]["uri"], mtls_auth_config["TruststoreUri"])

integration/combination/test_custom_rest_api_domains.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
class TestCustomRestApiDomains(BaseInternalTest):
1313
def test_custom_rest_api_domains_edge(self):
1414
self.create_and_verify_stack("combination/api_with_custom_domains_edge")
15+
1516
domain_name_list = self.get_stack_resources("AWS::ApiGateway::DomainName")
1617
self.assertEqual(1, len(domain_name_list))
1718

1819
domain_name_id = self.get_physical_id_by_type("AWS::ApiGateway::DomainName")
1920
api_gateway_client = self.client_provider.api_client
2021
result = api_gateway_client.get_domain_name(domainName=domain_name_id)
2122

22-
self.assertEqual("sam-gamma-edge.com", result["domainName"])
23+
if "FeatureToggle" in self.pipeline_prefix:
24+
self.assertEqual("ftl.sam-gamma-edge.com", result["domainName"])
25+
else:
26+
self.assertEqual("sam-gamma-edge.com", result["domainName"])
2327

2428
end_point_config = result["endpointConfiguration"]
2529
end_point_types = end_point_config["types"]
@@ -37,7 +41,11 @@ def test_custom_rest_api_domains_regional(self):
3741
api_gateway_client = self.client_provider.api_client
3842
result = api_gateway_client.get_domain_name(domainName=domain_name_id)
3943

40-
self.assertEqual("sam-gamma-regional.com", result["domainName"])
44+
if "FeatureToggle" in self.pipeline_prefix:
45+
self.assertEqual("ftl.sam-gamma-regional.com", result["domainName"])
46+
else:
47+
self.assertEqual("sam-gamma-regional.com", result["domainName"])
48+
4149
self.assertEqual("TLS_1_2", result["securityPolicy"])
4250

4351
end_point_config = result["endpointConfiguration"]

integration/helpers/base_test.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151

5252
STACK_NAME_PREFIX = "sam-integ-stack-"
5353
S3_BUCKET_PREFIX = "sam-integ-bucket-"
54+
FEATURE_TOGGLE_JSON_FILES = [
55+
"http_api_with_custom_domains_regional",
56+
"http_api_with_custom_domains_regional_ownership_verification",
57+
"api_with_custom_domains_edge",
58+
"api_with_custom_domains_regional",
59+
"api_with_custom_domains_regional_ownership_verification",
60+
]
5461

5562

5663
class BaseTest(TestCase):
@@ -154,13 +161,20 @@ def create_and_verify_stack(self, file_path, parameters=None, s3_uploader=None):
154161
s3_uploader: S3Uploader object
155162
Object for uploading files to s3
156163
"""
157-
folder, file_name = file_path.split("/")
158164

159165
# If template is too large, calling the method with self.s3_uploader to send the template to s3 then deploy
160166
self.create_stack(file_path, parameters, s3_uploader)
161-
self.expected_resource_path = str(Path(self.expected_dir, folder, file_name + ".json"))
167+
self.get_expected_json_file_name(file_path)
162168
self.verify_stack()
163169

170+
def get_expected_json_file_name(self, file_path):
171+
folder, file_name = file_path.split("/")
172+
173+
if "FeatureToggle" in self.pipeline_prefix and file_name in FEATURE_TOGGLE_JSON_FILES:
174+
self.expected_resource_path = str(Path(self.expected_dir, folder, file_name + "_feature_toggle.json"))
175+
else:
176+
self.expected_resource_path = str(Path(self.expected_dir, folder, file_name + ".json"))
177+
164178
def skip_using_service_detector(self, file_path):
165179
"""
166180
Skips the test if it cannot pass the test of
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{ "LogicalResourceId":"RecordSetGroupc911be5759", "ResourceType":"AWS::Route53::RecordSetGroup" },
3+
{ "LogicalResourceId":"MyApiDeployment", "ResourceType":"AWS::ApiGateway::Deployment" },
4+
{ "LogicalResourceId":"ApiGatewayDomainName299fac327d", "ResourceType":"AWS::ApiGateway::DomainName" },
5+
{ "LogicalResourceId":"MyApi", "ResourceType":"AWS::ApiGateway::RestApi" },
6+
{ "LogicalResourceId":"MyApiProdStage", "ResourceType":"AWS::ApiGateway::Stage" },
7+
{ "LogicalResourceId":"MyFunction", "ResourceType":"AWS::Lambda::Function" },
8+
{ "LogicalResourceId":"MyFunctionRole", "ResourceType":"AWS::IAM::Role" },
9+
{ "LogicalResourceId":"MyApigetBasePathMapping", "ResourceType":"AWS::ApiGateway::BasePathMapping" },
10+
{ "LogicalResourceId":"MyFunctionFetchPermissionProd", "ResourceType":"AWS::Lambda::Permission" }
11+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{ "LogicalResourceId":"MyFunctionImplicitGetPermissionProd", "ResourceType":"AWS::Lambda::Permission" },
3+
{ "LogicalResourceId":"ServerlessRestApiDeployment", "ResourceType":"AWS::ApiGateway::Deployment" },
4+
{ "LogicalResourceId":"ServerlessRestApipostBasePathMapping", "ResourceType":"AWS::ApiGateway::BasePathMapping" },
5+
{ "LogicalResourceId":"ServerlessRestApi", "ResourceType":"AWS::ApiGateway::RestApi" },
6+
{ "LogicalResourceId":"RecordSetGroupd17dced08c", "ResourceType":"AWS::Route53::RecordSetGroup" },
7+
{ "LogicalResourceId":"ServerlessRestApiProdStage", "ResourceType":"AWS::ApiGateway::Stage" },
8+
{ "LogicalResourceId":"ServerlessRestApigetBasePathMapping", "ResourceType":"AWS::ApiGateway::BasePathMapping" },
9+
{ "LogicalResourceId":"ApiGatewayDomainName98c928338d", "ResourceType":"AWS::ApiGateway::DomainName" },
10+
{ "LogicalResourceId":"MyFunction", "ResourceType":"AWS::Lambda::Function" },
11+
{ "LogicalResourceId":"MyFunctionImplicitPostPermissionProd", "ResourceType":"AWS::Lambda::Permission" },
12+
{ "LogicalResourceId":"MyFunctionRole", "ResourceType":"AWS::IAM::Role" }
13+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{ "LogicalResourceId":"MyFunctionImplicitGetPermissionProd", "ResourceType":"AWS::Lambda::Permission" },
3+
{ "LogicalResourceId":"ServerlessRestApiDeployment", "ResourceType":"AWS::ApiGateway::Deployment" },
4+
{ "LogicalResourceId":"ServerlessRestApipostBasePathMapping", "ResourceType":"AWS::ApiGateway::BasePathMapping" },
5+
{ "LogicalResourceId":"ServerlessRestApi", "ResourceType":"AWS::ApiGateway::RestApi" },
6+
{ "LogicalResourceId":"RecordSetGroupd17dced08c", "ResourceType":"AWS::Route53::RecordSetGroup" },
7+
{ "LogicalResourceId":"ServerlessRestApiProdStage", "ResourceType":"AWS::ApiGateway::Stage" },
8+
{ "LogicalResourceId":"ServerlessRestApigetBasePathMapping", "ResourceType":"AWS::ApiGateway::BasePathMapping" },
9+
{ "LogicalResourceId":"ApiGatewayDomainNamef593820b0b", "ResourceType":"AWS::ApiGateway::DomainName" },
10+
{ "LogicalResourceId":"MyFunction", "ResourceType":"AWS::Lambda::Function" },
11+
{ "LogicalResourceId":"MyFunctionImplicitPostPermissionProd", "ResourceType":"AWS::Lambda::Permission" },
12+
{ "LogicalResourceId":"MyFunctionRole", "ResourceType":"AWS::IAM::Role" }
13+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{ "LogicalResourceId":"MyFunctionImplicitGetPermission", "ResourceType":"AWS::Lambda::Permission" },
3+
{ "LogicalResourceId":"MyFunctionImplicitPostPermission", "ResourceType":"AWS::Lambda::Permission" },
4+
{ "LogicalResourceId":"MyApipostApiMapping", "ResourceType":"AWS::ApiGatewayV2::ApiMapping" },
5+
{ "LogicalResourceId":"MyApigetApiMapping", "ResourceType":"AWS::ApiGatewayV2::ApiMapping" },
6+
{ "LogicalResourceId":"MyApi", "ResourceType":"AWS::ApiGatewayV2::Api" },
7+
{ "LogicalResourceId":"RecordSetGroupd17dced08c", "ResourceType":"AWS::Route53::RecordSetGroup" },
8+
{ "LogicalResourceId":"MyApiProdStage", "ResourceType":"AWS::ApiGatewayV2::Stage" },
9+
{ "LogicalResourceId":"ApiGatewayDomainNameV26198c55d75", "ResourceType":"AWS::ApiGatewayV2::DomainName" },
10+
{ "LogicalResourceId":"MyFunction", "ResourceType":"AWS::Lambda::Function" },
11+
{ "LogicalResourceId":"MyFunctionRole", "ResourceType":"AWS::IAM::Role" }
12+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{ "LogicalResourceId":"MyFunctionImplicitGetPermission", "ResourceType":"AWS::Lambda::Permission" },
3+
{ "LogicalResourceId":"MyFunctionImplicitPostPermission", "ResourceType":"AWS::Lambda::Permission" },
4+
{ "LogicalResourceId":"MyApipostApiMapping", "ResourceType":"AWS::ApiGatewayV2::ApiMapping" },
5+
{ "LogicalResourceId":"MyApigetApiMapping", "ResourceType":"AWS::ApiGatewayV2::ApiMapping" },
6+
{ "LogicalResourceId":"MyApi", "ResourceType":"AWS::ApiGatewayV2::Api" },
7+
{ "LogicalResourceId":"RecordSetGroupd17dced08c", "ResourceType":"AWS::Route53::RecordSetGroup" },
8+
{ "LogicalResourceId":"MyApiProdStage", "ResourceType":"AWS::ApiGatewayV2::Stage" },
9+
{ "LogicalResourceId":"ApiGatewayDomainNameV2483cac8ea6", "ResourceType":"AWS::ApiGatewayV2::DomainName" },
10+
{ "LogicalResourceId":"MyFunction", "ResourceType":"AWS::Lambda::Function" },
11+
{ "LogicalResourceId":"MyFunctionRole", "ResourceType":"AWS::IAM::Role" }
12+
]

integration/resources/templates/combination/api_with_custom_domains_edge.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Parameters:
33
Type: String
44
MyEdgeDomainCert:
55
Type: String
6+
HostedZoneId:
7+
Type: String
68

79
Resources:
810
MyFunction:
@@ -41,5 +43,6 @@ Resources:
4143
BasePath:
4244
- /get
4345
Route53:
44-
HostedZoneId: Z1SKZDMQ2UR7IW
46+
HostedZoneId:
47+
Ref: HostedZoneId
4548
IpV6: true

integration/resources/templates/combination/api_with_custom_domains_regional.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Parameters:
33
Type: String
44
MyRestRegionalDomainCert:
55
Type: String
6+
HostedZoneId:
7+
Type: String
68

79
Globals:
810
Api:
@@ -20,7 +22,8 @@ Globals:
2022
- /get
2123
- /post
2224
Route53:
23-
HostedZoneId: Z1DTV8GVAVOHDR
25+
HostedZoneId:
26+
Ref: HostedZoneId
2427

2528
Resources:
2629
MyFunction:

0 commit comments

Comments
 (0)