Skip to content

Commit 3b267ca

Browse files
committed
feat(integration_test): add remaining templates
1 parent 00694b6 commit 3b267ca

File tree

7 files changed

+220
-1
lines changed

7 files changed

+220
-1
lines changed

integration_test/cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ steps:
130130
131131
node scripts/run-tests.js \
132132
--sequential \
133-
v2_firestore v2_database v2_storage v2_pubsub v2_eventarc \
133+
v2_firestore v2_database v2_storage v2_pubsub v2_eventarc v2_tasks v2_remoteconfig v2_scheduler v2_testlab v2_identity \
134134
--use-published-sdk=file:$$WHEEL_FILE
135135
136136
# Artifacts to store

integration_test/config/suites.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ suites:
129129
functions:
130130
- name: schedulerOnSchedule
131131
trigger: onSchedule
132+
decorator: on_schedule
132133
schedule: "every 1 minutes"
134+
collection: schedulerOnScheduleV2Tests
133135

134136
# V2 Task Queue functions
135137
- name: v2_tasks
@@ -139,7 +141,9 @@ suites:
139141
functions:
140142
- name: taskQueueOnEnqueue
141143
trigger: onTaskDispatched
144+
decorator: on_task_dispatched
142145
queueName: "v2-test-queue"
146+
collection: tasksOnTaskDispatchedTests
143147

144148
# V2 Identity triggers
145149
- name: v2_identity
@@ -149,8 +153,12 @@ suites:
149153
functions:
150154
- name: identityBeforeUserCreated
151155
trigger: beforeUserCreated
156+
decorator: before_user_created
157+
collection: identityBeforeUserCreatedTests
152158
- name: identityBeforeUserSignedIn
153159
trigger: beforeUserSignedIn
160+
decorator: before_user_signed_in
161+
collection: identityBeforeUserSignedInTests
154162

155163
# V2 Eventarc triggers
156164
- name: v2_eventarc
@@ -182,6 +190,8 @@ suites:
182190
functions:
183191
- name: testLabOnTestMatrixCompleted
184192
trigger: onTestMatrixCompleted
193+
decorator: on_test_matrix_completed
194+
collection: testLabOnTestMatrixCompletedTests
185195

186196
# V2 Remote Config triggers
187197
- name: v2_remoteconfig
@@ -191,3 +201,5 @@ suites:
191201
functions:
192202
- name: remoteConfigOnConfigUpdated
193203
trigger: onConfigUpdated
204+
decorator: on_config_updated
205+
collection: remoteConfigOnConfigUpdatedTests
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
Identity trigger tests for v2
3+
Test Run ID: {{testRunId}}
4+
"""
5+
6+
import os
7+
from firebase_admin import firestore
8+
from firebase_functions import identity_fn
9+
10+
REGION = "{{region}}"
11+
12+
{{#each functions}}
13+
@identity_fn.{{decorator}}(
14+
region=REGION,
15+
timeout_sec={{timeout}}
16+
)
17+
def {{name}}_{{../testRunId}}(event: identity_fn.AuthBlockingEvent) -> None:
18+
"""
19+
Test function: {{name}}
20+
Trigger: {{trigger}}
21+
"""
22+
# Extract uid from event data
23+
uid = event.data.uid
24+
25+
# Get project ID from environment
26+
project_id = os.environ.get('PROJECT_ID') or os.environ.get('GCLOUD_PROJECT') or "functions-integration-tests-v2"
27+
28+
# Prepare context data for storage
29+
context_data = {
30+
"eventId": event.event_id,
31+
"eventType": event.event_type,
32+
"timestamp": event.timestamp.isoformat() if hasattr(event.timestamp, 'isoformat') else str(event.timestamp),
33+
"resource": {
34+
"name": f"projects/{project_id}"
35+
}
36+
}
37+
38+
# Store context in Firestore for verification
39+
db = firestore.client()
40+
collection_name = "{{#if collection}}{{collection}}{{else}}{{name}}{{/if}}"
41+
db.collection(collection_name).document(uid).set(context_data)
42+
43+
# Return None (no modifications to user)
44+
return None
45+
46+
{{/each}}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Remote Config trigger tests for v2
3+
Test Run ID: {{testRunId}}
4+
"""
5+
6+
from firebase_admin import firestore
7+
from firebase_functions import remote_config_fn
8+
9+
REGION = "{{region}}"
10+
11+
{{#each functions}}
12+
@remote_config_fn.{{decorator}}(
13+
region=REGION,
14+
timeout_sec={{timeout}}
15+
)
16+
def {{name}}_{{../testRunId}}(event: remote_config_fn.CloudEvent[remote_config_fn.ConfigUpdateData]) -> None:
17+
"""
18+
Test function: {{name}}
19+
Trigger: {{trigger}}
20+
"""
21+
# Extract test_id from event data description
22+
test_id = event.data.description if event.data else None
23+
24+
if not test_id:
25+
print(f"Warning: No testId found in event data description")
26+
return
27+
28+
# Prepare context data for storage
29+
context_data = {
30+
"id": event.id,
31+
"time": event.time.isoformat() if hasattr(event.time, 'isoformat') else str(event.time),
32+
"type": event.type,
33+
"source": event.source,
34+
}
35+
36+
# Store context in Firestore for verification
37+
db = firestore.client()
38+
collection_name = "{{#if collection}}{{collection}}{{else}}{{name}}{{/if}}"
39+
db.collection(collection_name).document(test_id).set(context_data)
40+
41+
{{/each}}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Scheduler trigger tests for v2
3+
Test Run ID: {{testRunId}}
4+
"""
5+
6+
from firebase_admin import firestore
7+
from firebase_functions import scheduler_fn
8+
9+
REGION = "{{region}}"
10+
11+
{{#each functions}}
12+
@scheduler_fn.{{decorator}}(
13+
schedule="{{schedule}}",
14+
region=REGION,
15+
timeout_sec={{timeout}}
16+
)
17+
def {{name}}_{{../testRunId}}(event: scheduler_fn.ScheduledEvent) -> None:
18+
"""
19+
Test function: {{name}}
20+
Trigger: {{trigger}}
21+
Schedule: {{schedule}}
22+
"""
23+
# Extract test_id from job_name
24+
test_id = event.job_name
25+
if not test_id:
26+
print(f"Warning: No job_name found for scheduled function execution")
27+
return
28+
29+
# Store success flag in Firestore for verification
30+
db = firestore.client()
31+
collection_name = "{{#if collection}}{{collection}}{{else}}{{name}}{{/if}}"
32+
db.collection(collection_name).document(test_id).set({"success": True})
33+
34+
{{/each}}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
Task Queue trigger tests for v2
3+
Test Run ID: {{testRunId}}
4+
"""
5+
6+
import json
7+
import uuid
8+
from firebase_admin import firestore
9+
from firebase_functions import tasks_fn
10+
from firebase_functions.https_fn import CallableRequest
11+
12+
REGION = "{{region}}"
13+
14+
{{#each functions}}
15+
@tasks_fn.{{decorator}}(
16+
region=REGION,
17+
timeout_sec={{timeout}}
18+
)
19+
def {{name}}_{{../testRunId}}(request: CallableRequest) -> None:
20+
"""
21+
Test function: {{name}}
22+
Trigger: {{trigger}}
23+
"""
24+
# Extract test_id from request data
25+
data = request.data
26+
if not data or not isinstance(data, dict) or 'testId' not in data:
27+
print(f"Warning: Invalid data structure for tasks onTaskDispatched")
28+
return
29+
30+
test_id = data.get('testId')
31+
32+
# Prepare context data for storage
33+
# Generate a unique ID since CallableRequest doesn't have one
34+
context_data = {
35+
"id": str(uuid.uuid4()),
36+
"data": json.dumps(data) if data else "{}",
37+
}
38+
39+
# Store context in Firestore for verification
40+
db = firestore.client()
41+
collection_name = "{{#if collection}}{{collection}}{{else}}{{name}}{{/if}}"
42+
db.collection(collection_name).document(test_id).set(context_data)
43+
44+
{{/each}}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Test Lab trigger tests for v2
3+
Test Run ID: {{testRunId}}
4+
"""
5+
6+
from firebase_admin import firestore
7+
from firebase_functions import test_lab_fn
8+
9+
REGION = "{{region}}"
10+
11+
{{#each functions}}
12+
@test_lab_fn.{{decorator}}(
13+
region=REGION,
14+
timeout_sec={{timeout}}
15+
)
16+
def {{name}}_{{../testRunId}}(event: test_lab_fn.CloudEvent[test_lab_fn.TestMatrixCompletedData]) -> None:
17+
"""
18+
Test function: {{name}}
19+
Trigger: {{trigger}}
20+
"""
21+
# Extract test_id from client_info details
22+
test_id = event.data.client_info.details.get('testId') if event.data.client_info else None
23+
24+
if not test_id:
25+
print(f"Warning: No testId found in client_info details")
26+
return
27+
28+
# Prepare context data for storage
29+
context_data = {
30+
"testId": test_id,
31+
"id": event.id,
32+
"time": event.time.isoformat() if hasattr(event.time, 'isoformat') else str(event.time),
33+
"type": event.type,
34+
"state": str(event.data.state),
35+
}
36+
37+
# Store context in Firestore for verification
38+
db = firestore.client()
39+
collection_name = "{{#if collection}}{{collection}}{{else}}{{name}}{{/if}}"
40+
db.collection(collection_name).document(test_id).set(context_data)
41+
42+
{{/each}}

0 commit comments

Comments
 (0)