|
| 1 | +import pytest |
| 2 | +from localstack_snapshot.snapshots.transformer import RegexTransformer |
| 3 | + |
| 4 | +from localstack.services.cloudformation.v2.utils import is_v2_engine |
| 5 | +from localstack.testing.pytest import markers |
| 6 | +from localstack.utils.strings import long_uid |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.skipif(condition=not is_v2_engine(), reason="Requires the V2 engine") |
| 10 | +@markers.snapshot.skip_snapshot_verify( |
| 11 | + paths=[ |
| 12 | + "per-resource-events..*", |
| 13 | + "delete-describe..*", |
| 14 | + # |
| 15 | + "$..ChangeSetId", # An issue for the WIP executor |
| 16 | + # Before/After Context |
| 17 | + "$..Capabilities", |
| 18 | + "$..NotificationARNs", |
| 19 | + "$..IncludeNestedStacks", |
| 20 | + "$..Scope", |
| 21 | + "$..Details", |
| 22 | + "$..Parameters", |
| 23 | + "$..Replacement", |
| 24 | + "$..PolicyAction", |
| 25 | + "$..PhysicalResourceId", |
| 26 | + ] |
| 27 | +) |
| 28 | +class TestChangeSetConditions: |
| 29 | + @markers.aws.validated |
| 30 | + @pytest.mark.skip( |
| 31 | + reason="The inclusion of response parameters in executor is in progress, " |
| 32 | + "currently it cannot delete due to missing topic arn in the request" |
| 33 | + ) |
| 34 | + def test_condition_update_removes_resource( |
| 35 | + self, |
| 36 | + snapshot, |
| 37 | + capture_update_process, |
| 38 | + ): |
| 39 | + name1 = f"topic-name-1-{long_uid()}" |
| 40 | + name2 = f"topic-name-2-{long_uid()}" |
| 41 | + snapshot.add_transformer(RegexTransformer(name1, "topic-name-1")) |
| 42 | + snapshot.add_transformer(RegexTransformer(name2, "topic-name-2")) |
| 43 | + template_1 = { |
| 44 | + "Conditions": {"CreateTopic": {"Fn::Equals": ["true", "true"]}}, |
| 45 | + "Resources": { |
| 46 | + "SNSTopic": { |
| 47 | + "Type": "AWS::SNS::Topic", |
| 48 | + "Condition": "CreateTopic", |
| 49 | + "Properties": {"TopicName": name1}, |
| 50 | + } |
| 51 | + }, |
| 52 | + } |
| 53 | + template_2 = { |
| 54 | + "Conditions": {"CreateTopic": {"Fn::Equals": ["true", "false"]}}, |
| 55 | + "Resources": { |
| 56 | + "SNSTopic": { |
| 57 | + "Type": "AWS::SNS::Topic", |
| 58 | + "Condition": "CreateTopic", |
| 59 | + "Properties": {"TopicName": name1}, |
| 60 | + }, |
| 61 | + "TopicPlaceholder": { |
| 62 | + "Type": "AWS::SNS::Topic", |
| 63 | + "Properties": {"TopicName": name2}, |
| 64 | + }, |
| 65 | + }, |
| 66 | + } |
| 67 | + capture_update_process(snapshot, template_1, template_2) |
| 68 | + |
| 69 | + @markers.aws.validated |
| 70 | + def test_condition_update_adds_resource( |
| 71 | + self, |
| 72 | + snapshot, |
| 73 | + capture_update_process, |
| 74 | + ): |
| 75 | + name1 = f"topic-name-1-{long_uid()}" |
| 76 | + name2 = f"topic-name-2-{long_uid()}" |
| 77 | + snapshot.add_transformer(RegexTransformer(name1, "topic-name-1")) |
| 78 | + snapshot.add_transformer(RegexTransformer(name2, "topic-name-2")) |
| 79 | + template_1 = { |
| 80 | + "Conditions": {"CreateTopic": {"Fn::Equals": ["true", "false"]}}, |
| 81 | + "Resources": { |
| 82 | + "SNSTopic": { |
| 83 | + "Type": "AWS::SNS::Topic", |
| 84 | + "Condition": "CreateTopic", |
| 85 | + "Properties": {"TopicName": name1}, |
| 86 | + }, |
| 87 | + "TopicPlaceholder": { |
| 88 | + "Type": "AWS::SNS::Topic", |
| 89 | + "Properties": {"TopicName": name2}, |
| 90 | + }, |
| 91 | + }, |
| 92 | + } |
| 93 | + template_2 = { |
| 94 | + "Conditions": {"CreateTopic": {"Fn::Equals": ["true", "true"]}}, |
| 95 | + "Resources": { |
| 96 | + "SNSTopic": { |
| 97 | + "Type": "AWS::SNS::Topic", |
| 98 | + "Condition": "CreateTopic", |
| 99 | + "Properties": {"TopicName": name1}, |
| 100 | + }, |
| 101 | + "TopicPlaceholder": { |
| 102 | + "Type": "AWS::SNS::Topic", |
| 103 | + "Properties": {"TopicName": name2}, |
| 104 | + }, |
| 105 | + }, |
| 106 | + } |
| 107 | + capture_update_process(snapshot, template_1, template_2) |
| 108 | + |
| 109 | + @markers.aws.validated |
| 110 | + @pytest.mark.skip( |
| 111 | + reason="The inclusion of response parameters in executor is in progress, " |
| 112 | + "currently it cannot delete due to missing topic arn in the request" |
| 113 | + ) |
| 114 | + def test_condition_add_new_negative_condition_to_existent_resource( |
| 115 | + self, |
| 116 | + snapshot, |
| 117 | + capture_update_process, |
| 118 | + ): |
| 119 | + name1 = f"topic-name-1-{long_uid()}" |
| 120 | + name2 = f"topic-name-2-{long_uid()}" |
| 121 | + snapshot.add_transformer(RegexTransformer(name1, "topic-name-1")) |
| 122 | + snapshot.add_transformer(RegexTransformer(name2, "topic-name-2")) |
| 123 | + template_1 = { |
| 124 | + "Resources": { |
| 125 | + "SNSTopic": { |
| 126 | + "Type": "AWS::SNS::Topic", |
| 127 | + "Properties": {"TopicName": name1}, |
| 128 | + }, |
| 129 | + }, |
| 130 | + } |
| 131 | + template_2 = { |
| 132 | + "Conditions": {"CreateTopic": {"Fn::Equals": ["true", "false"]}}, |
| 133 | + "Resources": { |
| 134 | + "SNSTopic": { |
| 135 | + "Type": "AWS::SNS::Topic", |
| 136 | + "Condition": "CreateTopic", |
| 137 | + "Properties": {"TopicName": name1}, |
| 138 | + }, |
| 139 | + "TopicPlaceholder": { |
| 140 | + "Type": "AWS::SNS::Topic", |
| 141 | + "Properties": {"TopicName": name2}, |
| 142 | + }, |
| 143 | + }, |
| 144 | + } |
| 145 | + capture_update_process(snapshot, template_1, template_2) |
| 146 | + |
| 147 | + @markers.aws.validated |
| 148 | + def test_condition_add_new_positive_condition_to_existent_resource( |
| 149 | + self, |
| 150 | + snapshot, |
| 151 | + capture_update_process, |
| 152 | + ): |
| 153 | + name1 = f"topic-name-1-{long_uid()}" |
| 154 | + name2 = f"topic-name-2-{long_uid()}" |
| 155 | + snapshot.add_transformer(RegexTransformer(name1, "topic-name-1")) |
| 156 | + snapshot.add_transformer(RegexTransformer(name2, "topic-name-2")) |
| 157 | + template_1 = { |
| 158 | + "Resources": { |
| 159 | + "SNSTopic1": { |
| 160 | + "Type": "AWS::SNS::Topic", |
| 161 | + "Properties": {"TopicName": name1}, |
| 162 | + }, |
| 163 | + }, |
| 164 | + } |
| 165 | + template_2 = { |
| 166 | + "Conditions": {"CreateTopic": {"Fn::Equals": ["true", "true"]}}, |
| 167 | + "Resources": { |
| 168 | + "SNSTopic1": { |
| 169 | + "Type": "AWS::SNS::Topic", |
| 170 | + "Condition": "CreateTopic", |
| 171 | + "Properties": {"TopicName": name1}, |
| 172 | + }, |
| 173 | + "SNSTopic2": { |
| 174 | + "Type": "AWS::SNS::Topic", |
| 175 | + "Condition": "CreateTopic", |
| 176 | + "Properties": {"TopicName": name2}, |
| 177 | + }, |
| 178 | + }, |
| 179 | + } |
| 180 | + capture_update_process(snapshot, template_1, template_2) |
0 commit comments