|
14 | 14 | from sentry.projects.services.project import project_service |
15 | 15 | from sentry.silo.base import SiloMode |
16 | 16 | from sentry.testutils.cases import IntegrationTestCase |
| 17 | +from sentry.testutils.helpers.options import override_options |
17 | 18 | from sentry.testutils.silo import assume_test_silo_mode, control_silo_test |
18 | 19 | from sentry.users.services.user.serial import serialize_rpc_user |
19 | 20 |
|
@@ -157,67 +158,94 @@ def test_lambda_list(self, mock_react_view, mock_gen_aws_client, mock_get_suppor |
157 | 158 |
|
158 | 159 | @patch("sentry.integrations.aws_lambda.integration.get_supported_functions") |
159 | 160 | @patch("sentry.integrations.aws_lambda.integration.gen_aws_client") |
160 | | - def test_lambda_setup_layer_success(self, mock_gen_aws_client, mock_get_supported_functions): |
161 | | - mock_client = mock_gen_aws_client.return_value |
162 | | - mock_client.update_function_configuration = MagicMock() |
163 | | - mock_client.describe_account = MagicMock(return_value={"Account": {"Name": "my_name"}}) |
164 | | - |
165 | | - mock_get_supported_functions.return_value = [ |
166 | | - { |
167 | | - "FunctionName": "lambdaA", |
168 | | - "Runtime": "nodejs12.x", |
169 | | - "FunctionArn": "arn:aws:lambda:us-east-2:599817902985:function:lambdaA", |
170 | | - }, |
171 | | - { |
172 | | - "FunctionName": "lambdaB", |
173 | | - "Runtime": "nodejs10.x", |
174 | | - "FunctionArn": "arn:aws:lambda:us-east-2:599817902985:function:lambdaB", |
175 | | - }, |
176 | | - ] |
177 | | - |
178 | | - aws_external_id = "12-323" |
179 | | - self.pipeline.state.step_index = 2 |
180 | | - self.pipeline.state.data = { |
181 | | - "region": region, |
182 | | - "account_number": account_number, |
183 | | - "aws_external_id": aws_external_id, |
184 | | - "project_id": self.projectA.id, |
185 | | - } |
186 | | - |
187 | | - with assume_test_silo_mode(SiloMode.REGION): |
188 | | - sentry_project_dsn = ProjectKey.get_default(project=self.projectA).get_dsn(public=True) |
189 | | - |
190 | | - # TODO: pass in lambdaA=false |
191 | | - # having issues with reading json data |
192 | | - # request.POST looks like {"lambdaB": "True"} |
193 | | - # string instead of boolean |
194 | | - resp = self.client.post(self.setup_path, {"lambdaB": "true", "lambdaA": "false"}) |
195 | | - |
196 | | - assert resp.status_code == 200 |
197 | | - |
198 | | - mock_client.update_function_configuration.assert_called_once_with( |
199 | | - FunctionName="lambdaB", |
200 | | - Layers=["arn:aws:lambda:us-east-2:1234:layer:my-layer:3"], |
201 | | - Environment={ |
202 | | - "Variables": { |
203 | | - "NODE_OPTIONS": "-r @sentry/serverless/dist/awslambda-auto", |
204 | | - "SENTRY_DSN": sentry_project_dsn, |
205 | | - "SENTRY_TRACES_SAMPLE_RATE": "1.0", |
| 161 | + def test_node_lambda_setup_layer_success( |
| 162 | + self, |
| 163 | + mock_gen_aws_client, |
| 164 | + mock_get_supported_functions, |
| 165 | + ): |
| 166 | + for layer_name, layer_version, expected_node_options in [ |
| 167 | + ("SentryNodeServerlessSDKv7", "5", "-r @sentry/serverless/dist/awslambda-auto"), |
| 168 | + ("SentryNodeServerlessSDK", "168", "-r @sentry/serverless/dist/awslambda-auto"), |
| 169 | + ("SentryNodeServerlessSDK", "235", "-r @sentry/serverless/dist/awslambda-auto"), |
| 170 | + ("SentryNodeServerlessSDK", "236", "-r @sentry/aws-serverless/awslambda-auto"), |
| 171 | + ("SentryNodeServerlessSDKv8", "3", "-r @sentry/aws-serverless/awslambda-auto"), |
| 172 | + ("SentryNodeServerlessSDKv9", "238", "-r @sentry/aws-serverless/awslambda-auto"), |
| 173 | + ]: |
| 174 | + with override_options( |
| 175 | + { |
| 176 | + "aws-lambda.node.layer-name": layer_name, |
| 177 | + "aws-lambda.node.layer-version": layer_version, |
| 178 | + } |
| 179 | + ): |
| 180 | + # Ensure we reset everything |
| 181 | + self.setUp() |
| 182 | + mock_get_supported_functions.reset_mock() |
| 183 | + mock_gen_aws_client.reset_mock() |
| 184 | + |
| 185 | + mock_client = mock_gen_aws_client.return_value |
| 186 | + mock_client.update_function_configuration = MagicMock() |
| 187 | + mock_client.describe_account = MagicMock( |
| 188 | + return_value={"Account": {"Name": "my_name"}} |
| 189 | + ) |
| 190 | + |
| 191 | + mock_get_supported_functions.return_value = [ |
| 192 | + { |
| 193 | + "FunctionName": "lambdaA", |
| 194 | + "Runtime": "nodejs12.x", |
| 195 | + "FunctionArn": "arn:aws:lambda:us-east-2:599817902985:function:lambdaA", |
| 196 | + }, |
| 197 | + { |
| 198 | + "FunctionName": "lambdaB", |
| 199 | + "Runtime": "nodejs10.x", |
| 200 | + "FunctionArn": "arn:aws:lambda:us-east-2:599817902985:function:lambdaB", |
| 201 | + }, |
| 202 | + ] |
| 203 | + |
| 204 | + aws_external_id = "12-323" |
| 205 | + self.pipeline.state.step_index = 2 |
| 206 | + self.pipeline.state.data = { |
| 207 | + "region": region, |
| 208 | + "account_number": account_number, |
| 209 | + "aws_external_id": aws_external_id, |
| 210 | + "project_id": self.projectA.id, |
206 | 211 | } |
207 | | - }, |
208 | | - ) |
209 | 212 |
|
210 | | - integration = Integration.objects.get(provider=self.provider.key) |
211 | | - assert integration.name == "my_name us-east-2" |
212 | | - assert integration.external_id == "599817902985-us-east-2" |
213 | | - assert integration.metadata == { |
214 | | - "region": region, |
215 | | - "account_number": account_number, |
216 | | - "aws_external_id": aws_external_id, |
217 | | - } |
218 | | - assert OrganizationIntegration.objects.filter( |
219 | | - integration=integration, organization_id=self.organization.id |
220 | | - ) |
| 213 | + with assume_test_silo_mode(SiloMode.REGION): |
| 214 | + sentry_project_dsn = ProjectKey.get_default(project=self.projectA).get_dsn( |
| 215 | + public=True |
| 216 | + ) |
| 217 | + |
| 218 | + # TODO: pass in lambdaA=false |
| 219 | + # having issues with reading json data |
| 220 | + # request.POST looks like {"lambdaB": "True"} |
| 221 | + # string instead of boolean |
| 222 | + resp = self.client.post(self.setup_path, {"lambdaB": "true", "lambdaA": "false"}) |
| 223 | + |
| 224 | + assert resp.status_code == 200 |
| 225 | + |
| 226 | + mock_client.update_function_configuration.assert_called_once_with( |
| 227 | + FunctionName="lambdaB", |
| 228 | + Layers=[f"arn:aws:lambda:us-east-2:1234:layer:{layer_name}:{layer_version}"], |
| 229 | + Environment={ |
| 230 | + "Variables": { |
| 231 | + "NODE_OPTIONS": expected_node_options, |
| 232 | + "SENTRY_DSN": sentry_project_dsn, |
| 233 | + "SENTRY_TRACES_SAMPLE_RATE": "1.0", |
| 234 | + } |
| 235 | + }, |
| 236 | + ) |
| 237 | + |
| 238 | + integration = Integration.objects.get(provider=self.provider.key) |
| 239 | + assert integration.name == "my_name us-east-2" |
| 240 | + assert integration.external_id == "599817902985-us-east-2" |
| 241 | + assert integration.metadata == { |
| 242 | + "region": region, |
| 243 | + "account_number": account_number, |
| 244 | + "aws_external_id": aws_external_id, |
| 245 | + } |
| 246 | + assert OrganizationIntegration.objects.filter( |
| 247 | + integration=integration, organization_id=self.organization.id |
| 248 | + ) |
221 | 249 |
|
222 | 250 | @patch("sentry.integrations.aws_lambda.integration.get_supported_functions") |
223 | 251 | @patch("sentry.integrations.aws_lambda.integration.gen_aws_client") |
|
0 commit comments