Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where 2nd Gen firestore functions were mistakenly parsed as pubsub function #6456

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Enable [preferRest](https://firebase.google.com/docs/reference/admin/node/firebase-admin.firestore.firestoresettings.md#firestoresettingspreferrest) option by default for Firestore functions. (#6147)
- Fixed an issue with deploying multilevel grouped functions containing v2 functions. (#6419)
5 changes: 4 additions & 1 deletion src/gcp/cloudfunctionsv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,10 @@ export function endpointFromFunction(gcfFunction: OutputCloudFunction): backend.
} else if (gcfFunction.eventTrigger) {
const eventFilters: Record<string, string> = {};
const eventFilterPathPatterns: Record<string, string> = {};
if (gcfFunction.eventTrigger.pubsubTopic) {
if (
gcfFunction.eventTrigger.pubsubTopic &&
gcfFunction.eventTrigger.eventType === PUBSUB_PUBLISH_EVENT
) {
eventFilters.topic = gcfFunction.eventTrigger.pubsubTopic;
} else {
for (const eventFilter of gcfFunction.eventTrigger.eventFilters || []) {
Expand Down
40 changes: 40 additions & 0 deletions src/test/gcp/cloudfunctionsv2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,46 @@ describe("cloudfunctionsv2", () => {
},
})
).to.deep.equal(want);

// And again with a pattern match event trigger
want = {
...want,
eventTrigger: {
eventType: "google.cloud.firestore.document.v1.written",
eventFilters: {
database: "(default)",
namespace: "(default)",
},
eventFilterPathPatterns: {
document: "users/{userId}",
},
retry: false,
},
};
expect(
cloudfunctionsv2.endpointFromFunction({
...HAVE_CLOUD_FUNCTION_V2,
eventTrigger: {
eventType: "google.cloud.firestore.document.v1.written",
eventFilters: [
{
attribute: "database",
value: "(default)",
},
{
attribute: "namespace",
value: "(default)",
},
{
attribute: "document",
value: "users/{userId}",
operator: "match-path-pattern",
},
],
pubsubTopic: "eventarc-us-central1-abc", // firestore triggers use pubsub as transport
},
})
).to.deep.equal(want);
});

it("should translate custom event triggers", () => {
Expand Down