8000 Refactor CFn conditions & mappings by dominikschubert · Pull Request #8546 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

Refactor CFn conditions & mappings #8546

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 14 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Prev Previous commit
Next Next commit
test cfn mappings
  • Loading branch information
dominikschubert committed Jun 26, 2023
commit c8af1c8bf0b34eac978d02149ca3e6fb217c05c9
28 changes: 27 additions & 1 deletion tests/integration/cloudformation/engine/test_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,30 @@ def test_mapping_maximum_nesting_depth(self, aws_client, cleanups, snapshot):
{"ParameterKey": "TopicNameSuffixSelector", "ParameterValue": "A"},
],
)
snapshot.match("mapping_nonexisting_key_exc", e.value.response)
snapshot.match("mapping_maximum_level_exc", e.value.response)

@pytest.mark.aws_validated
def test_mapping_minimum_nesting_depth(self, aws_client, cleanups, snapshot):
"""
Tries to deploy a template containing a mapping with a nesting depth of 1.
The required depth is 2, so it should fail for a single level
"""
topic_name = f"test-topic-{short_uid()}"
stack_name = f"test-stack-{short_uid()}"
cleanups.append(lambda: aws_client.cloudformation.delete_stack(StackName=stack_name))
template_body = load_file(
os.path.join(THIS_DIR, "../../templates/mappings/simple-mapping-single-level.yaml")
)

with pytest.raises(aws_client.cloudformation.exceptions.ClientError) as e:
aws_client.cloudformation.create_change_set(
StackName=stack_name,
ChangeSetName="initial",
TemplateBody=template_body,
ChangeSetType="CREATE",
Parameters=[
{"ParameterKey": "TopicName", "ParameterValue": topic_name},
{"ParameterKey": "TopicNameSuffixSelector", "ParameterValue": "A"},
],
)
snapshot.match("mapping_minimum_level_exc", e.value.response)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tests/integration/cloudformation/engine/test_mappings.py::TestCloudFormationMappings::test_mapping_with_nonexisting_key": {
"recorded-date": "12-06-2023, 11:54:01",
"recorded-date": "12-06-2023, 16:47:23",
"recorded-content": {
"mapping_nonexisting_key_exc": {
"Error": {
Expand All @@ -16,7 +16,7 @@
}
},
"tests/integration/cloudformation/engine/test_mappings.py::TestCloudFormationMappings::test_mapping_with_invalid_refs": {
"recorded-date": "12-06-2023, 11:54:01",
"recorded-date": "12-06-2023, 16:47:24",
"recorded-content": {
"mapping_invalid_ref_exc": {
"Error": {
Expand All @@ -32,9 +32,9 @@
}
},
"tests/integration/cloudformation/engine/test_mappings.py::TestCloudFormationMappings::test_mapping_maximum_nesting_depth": {
"recorded-date": "12-06-2023, 11:54:02",
"recorded-date": "12-06-2023, 16:47:24",
"recorded-content": {
"mapping_nonexisting_key_exc": {
"mapping_maximum_level_exc": {
"Error": {
"Code": "ValidationError",
"Message": "Template format error: Every Mappings attribute must be a String or a List.",
Expand All @@ -46,5 +46,21 @@
}
}
}
},
"tests/integration/cloudformation/engine/test_mappings.py::TestCloudFormationMappings::test_mapping_minimum_nesting_depth": {
"recorded-date": "12-06-2023, 16:47:25",
"recorded-content": {
"mapping_minimum_level_exc": {
"Error": {
"Code": "ValidationError",
"Message": "Template format error: Every Mappings member A must be a map",
"Type": "Sender"
},
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 400
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Parameters:
TopicName:
Type: String

TopicNameSuffixSelector:
Type: String

Resources:
MyTopic:
Type: AWS::SNS::Topic
Properties:
TopicName:
"Fn::Join":
- "-"
- - !Ref TopicName
- !FindInMap [TopicSuffixMap, !Ref TopicNameSuffixSelector]

Mappings:
TopicSuffixMap:
A: suffix-a
B: suffix-b
0