|
17 | 17 |
|
18 | 18 | from pytest import raises |
19 | 19 |
|
20 | | -from firebase_functions import https_fn, options, params |
| 20 | +from firebase_functions import alerts_fn, https_fn, options, params |
| 21 | +from firebase_functions.alerts import app_distribution_fn, billing_fn, crashlytics_fn, performance_fn |
21 | 22 | from firebase_functions.private.serving import functions_as_yaml, merge_required_apis |
22 | 23 |
|
23 | 24 | # pylint: disable=protected-access |
24 | 25 |
|
| 26 | +ALERT_SECRET = params.SecretParam("GITLAB_PERSONAL_ACCESS_TOKEN") |
| 27 | + |
25 | 28 |
|
26 | 29 | @https_fn.on_call() |
27 | 30 | def asamplefunction(_): |
@@ -196,3 +199,104 @@ def test_invoker_with_no_element_throws(): |
196 | 199 | AssertionError, match="HttpsOptions: Invalid option for invoker - must be a non-empty list." |
197 | 200 | ): |
198 | 201 | options.HttpsOptions(invoker=[])._endpoint(func_name="test") |
| 202 | + |
| 203 | + |
| 204 | +def _assert_alert_endpoint_options(endpoint, expected_alert_type, expect_app_id: str | None = None): |
| 205 | + assert endpoint.region == ["europe-west1"] |
| 206 | + assert endpoint.maxInstances == 1 |
| 207 | + assert endpoint.secretEnvironmentVariables == [{"key": "GITLAB_PERSONAL_ACCESS_TOKEN"}] |
| 208 | + assert endpoint.eventTrigger["retry"] is True |
| 209 | + assert endpoint.eventTrigger["eventFilters"]["alerttype"] == expected_alert_type |
| 210 | + if expect_app_id is None: |
| 211 | + assert "appid" not in endpoint.eventTrigger["eventFilters"] |
| 212 | + else: |
| 213 | + assert endpoint.eventTrigger["eventFilters"]["appid"] == expect_app_id |
| 214 | + |
| 215 | + |
| 216 | +def test_crashlytics_options_preserved_in_alert_endpoint(): |
| 217 | + @crashlytics_fn.on_new_fatal_issue_published( |
| 218 | + secrets=[ALERT_SECRET], |
| 219 | + region="europe-west1", |
| 220 | + max_instances=1, |
| 221 | + retry=True, |
| 222 | + app_id="app-123", |
| 223 | + ) |
| 224 | + def sample(_event): |
| 225 | + return None |
| 226 | + |
| 227 | + _assert_alert_endpoint_options( |
| 228 | + sample.__firebase_endpoint__, |
| 229 | + "crashlytics.newFatalIssue", |
| 230 | + expect_app_id="app-123", |
| 231 | + ) |
| 232 | + |
| 233 | + |
| 234 | +def test_app_distribution_options_preserved_in_alert_endpoint(): |
| 235 | + @app_distribution_fn.on_new_tester_ios_device_published( |
| 236 | + secrets=[ALERT_SECRET], |
| 237 | + region="europe-west1", |
| 238 | + max_instances=1, |
| 239 | + retry=True, |
| 240 | + app_id="app-123", |
| 241 | + ) |
| 242 | + def sample(_event): |
| 243 | + return None |
| 244 | + |
| 245 | + _assert_alert_endpoint_options( |
| 246 | + sample.__firebase_endpoint__, |
| 247 | + "appDistribution.newTesterIosDevice", |
| 248 | + expect_app_id="app-123", |
| 249 | + ) |
| 250 | + |
| 251 | + |
| 252 | +def test_performance_options_preserved_in_alert_endpoint(): |
| 253 | + @performance_fn.on_threshold_alert_published( |
| 254 | + secrets=[ALERT_SECRET], |
| 255 | + region="europe-west1", |
| 256 | + max_instances=1, |
| 257 | + retry=True, |
| 258 | + app_id="app-123", |
| 259 | + ) |
| 260 | + def sample(_event): |
| 261 | + return None |
| 262 | + |
| 263 | + _assert_alert_endpoint_options( |
| 264 | + sample.__firebase_endpoint__, |
| 265 | + "performance.threshold", |
| 266 | + expect_app_id="app-123", |
| 267 | + ) |
| 268 | + |
| 269 | + |
| 270 | +def test_billing_options_preserved_in_alert_endpoint(): |
| 271 | + @billing_fn.on_plan_update_published( |
| 272 | + secrets=[ALERT_SECRET], |
| 273 | + region="europe-west1", |
| 274 | + max_instances=1, |
| 275 | + retry=True, |
| 276 | + ) |
| 277 | + def sample(_event): |
| 278 | + return None |
| 279 | + |
| 280 | + _assert_alert_endpoint_options( |
| 281 | + sample.__firebase_endpoint__, |
| 282 | + "billing.planUpdate", |
| 283 | + ) |
| 284 | + |
| 285 | + |
| 286 | +def test_firebase_alert_options_preserved_in_alert_endpoint(): |
| 287 | + @alerts_fn.on_alert_published( |
| 288 | + alert_type=alerts_fn.AlertType.CRASHLYTICS_NEW_FATAL_ISSUE, |
| 289 | + secrets=[ALERT_SECRET], |
| 290 | + region="europe-west1", |
| 291 | + max_instances=1, |
| 292 | + retry=True, |
| 293 | + app_id="app-123", |
| 294 | + ) |
| 295 | + def sample(_event): |
| 296 | + return None |
| 297 | + |
| 298 | + _assert_alert_endpoint_options( |
| 299 | + sample.__firebase_endpoint__, |
| 300 | + "crashlytics.newFatalIssue", |
| 301 | + expect_app_id="app-123", |
| 302 | + ) |
0 commit comments