Skip to content

Commit 00694b6

Browse files
committed
feat(integration_test): add eventarc and pubsub suites
1 parent 43e1ee7 commit 00694b6

File tree

4 files changed

+108
-3
lines changed

4 files changed

+108
-3
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 \
133+
v2_firestore v2_database v2_storage v2_pubsub v2_eventarc \
134134
--use-published-sdk=file:$$WHEEL_FILE
135135
136136
# Artifacts to store

integration_test/config/suites.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ suites:
8585
functions:
8686
- name: pubsubOnMessagePublished
8787
trigger: onMessagePublished
88-
topic: "firebase-functions-pubsub-v2"
88+
decorator: on_message_published
89+
eventType: messagePublished
90+
topic: custom_message_tests
91+
collection: pubsubOnMessagePublishedTests
8992

9093
# V2 Storage triggers
9194
- name: v2_storage
@@ -157,7 +160,9 @@ suites:
157160
functions:
158161
- name: eventarcOnCustomEventPublished
159162
trigger: onCustomEventPublished
160-
eventType: "test.event.v1"
163+
decorator: on_custom_event_published
164+
eventType: achieved-leaderboard
165+
collection: eventarcOnCustomEventPublishedTests
161166

162167
# V2 Alerts triggers
163168
- name: v2_alerts
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
Eventarc trigger tests for v2
3+
Test Run ID: {{testRunId}}
4+
"""
5+
6+
import json
7+
from firebase_admin import firestore
8+
from firebase_functions import eventarc_fn
9+
10+
REGION = "{{region}}"
11+
12+
{{#each functions}}
13+
@eventarc_fn.{{decorator}}(
14+
event_type="{{eventType}}",
15+
region=REGION,
16+
timeout_sec={{timeout}}
17+
)
18+
def {{name}}_{{../testRunId}}(event: eventarc_fn.CloudEvent) -> None:
19+
"""
20+
Test function: {{name}}
21+
Trigger: {{trigger}}
22+
Event Type: {{eventType}}
23+
"""
24+
# Extract test_id from event data
25+
test_id = event.data.get('testId') if event.data else None
26+
27+
if not test_id:
28+
print(f"Warning: No testId found in event data")
29+
return
30+
31+
# Prepare context data for storage
32+
context_data = {
33+
"id": event.id,
34+
"time": event.time.isoformat() if hasattr(event.time, 'isoformat') else str(event.time),
35+
"type": event.type,
36+
"source": event.source,
37+
# Stringify the data dict for storage (matching JS behavior)
38+
"data": json.dumps(event.data) if event.data else "{}"
39+
}
40+
41+
# Store context in Firestore for verification
42+
db = firestore.client()
43+
collection_name = "{{#if collection}}{{collection}}{{else}}{{name}}{{/if}}"
44+
db.collection(collection_name).document(test_id).set(context_data)
45+
46+
{{/each}}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
Pub/Sub trigger tests for v2
3+
Test Run ID: {{testRunId}}
4+
"""
5+
6+
import json
7+
from firebase_admin import firestore
8+
from firebase_functions import pubsub_fn
9+
10+
REGION = "{{region}}"
11+
12+
{{#each functions}}
13+
@pubsub_fn.{{decorator}}(
14+
topic="{{topic}}",
15+
region=REGION,
16+
timeout_sec={{timeout}}
17+
)
18+
def {{name}}_{{../testRunId}}(event: pubsub_fn.CloudEvent[pubsub_fn.MessagePublishedData[dict]]) -> None:
19+
"""
20+
Test function: {{name}}
21+
Trigger: {{trigger}}
22+
Topic: {{topic}}
23+
"""
24+
# Extract test_id from message JSON data
25+
message = event.data.message
26+
message_json = message.json
27+
test_id = message_json.get('testId') if message_json else None
28+
29+
if not test_id:
30+
print(f"Warning: No testId found in message")
31+
return
32+
33+
# Prepare context data for storage
34+
context_data = {
35+
"id": event.id,
36+
"time": event.time,
37+
"type": f"google.cloud.pubsub.topic.v1.{{eventType}}",
38+
"source": event.source,
39+
# Stringify the message object for storage (matching JS behavior)
40+
"message": json.dumps({
41+
"data": message.data,
42+
"messageId": message.message_id,
43+
"publishTime": message.publish_time,
44+
"attributes": message.attributes,
45+
"orderingKey": message.ordering_key,
46+
})
47+
}
48+
49+
# Store context in Firestore for verification
50+
db = firestore.client()
51+
collection_name = "{{#if collection}}{{collection}}{{else}}{{name}}{{/if}}"
52+
db.collection(collection_name).document(test_id).set(context_data)
53+
54+
{{/each}}

0 commit comments

Comments
 (0)