diff --git a/scripts/bin-test/sources/commonjs-preserve/index.js b/scripts/bin-test/sources/commonjs-preserve/index.js new file mode 100644 index 000000000..7c953dec8 --- /dev/null +++ b/scripts/bin-test/sources/commonjs-preserve/index.js @@ -0,0 +1,18 @@ +const functions = require("firebase-functions"); +const functionsv2 = require("firebase-functions/v2"); + +exports.v1http = functions.https.onRequest((req, resp) => { + resp.status(200).send("PASS"); +}); + +exports.v1httpPreserve = functions + .runWith({ preserveExternalChanges: true }) + .https.onRequest((req, resp) => { + resp.status(200).send("PASS"); + }); + +functionsv2.setGlobalOptions({ preserveExternalChanges: true }); + +exports.v2http = functionsv2.https.onRequest((req, resp) => { + resp.status(200).send("PASS"); +}); diff --git a/scripts/bin-test/sources/commonjs-preserve/package.json b/scripts/bin-test/sources/commonjs-preserve/package.json new file mode 100644 index 000000000..7fdf4e928 --- /dev/null +++ b/scripts/bin-test/sources/commonjs-preserve/package.json @@ -0,0 +1,3 @@ +{ + "name": "commonjs-preserve" +} diff --git a/scripts/bin-test/test.ts b/scripts/bin-test/test.ts index 420f888a6..b15012d70 100644 --- a/scripts/bin-test/test.ts +++ b/scripts/bin-test/test.ts @@ -13,26 +13,44 @@ const TIMEOUT_L = 10_000; const TIMEOUT_M = 5_000; const TIMEOUT_S = 1_000; +const DEFAULT_OPTIONS = { + availableMemoryMb: null, + maxInstances: null, + minInstances: null, + timeoutSeconds: null, + vpc: null, + serviceAccountEmail: null, + ingressSettings: null, +}; + +const DEFAULT_V1_OPTIONS = { ...DEFAULT_OPTIONS }; + +const DEFAULT_V2_OPTIONS = { ...DEFAULT_OPTIONS, concurrency: null }; + const BASE_STACK = { endpoints: { v1http: { + ...DEFAULT_V1_OPTIONS, platform: "gcfv1", entryPoint: "v1http", httpsTrigger: {}, }, v1callable: { + ...DEFAULT_V1_OPTIONS, platform: "gcfv1", entryPoint: "v1callable", labels: {}, callableTrigger: {}, }, v2http: { + ...DEFAULT_V2_OPTIONS, platform: "gcfv2", entryPoint: "v2http", labels: {}, httpsTrigger: {}, }, v2callable: { + ...DEFAULT_V2_OPTIONS, platform: "gcfv2", entryPoint: "v2callable", labels: {}, @@ -82,7 +100,7 @@ async function startBin( const getPort = promisify(portfinder.getPort) as () => Promise; const port = await getPort(); - const proc = subprocess.spawn("./node_modules/.bin/firebase-functions", [], { + const proc = subprocess.spawn("npx", ["firebase-functions"], { cwd: path.resolve(tc.modulePath), env: { PATH: process.env.PATH, @@ -183,11 +201,13 @@ describe("functions.yaml", () => { endpoints: { ...BASE_STACK.endpoints, "g1-groupedhttp": { + ...DEFAULT_V1_OPTIONS, platform: "gcfv1", entryPoint: "g1.groupedhttp", httpsTrigger: {}, }, "g1-groupedcallable": { + ...DEFAULT_V1_OPTIONS, platform: "gcfv1", entryPoint: "g1.groupedcallable", labels: {}, @@ -196,6 +216,33 @@ describe("functions.yaml", () => { }, }, }, + { + name: "preserveChange", + modulePath: "./scripts/bin-test/sources/commonjs-preserve", + expected: { + endpoints: { + v1http: { + ...DEFAULT_V1_OPTIONS, + platform: "gcfv1", + entryPoint: "v1http", + httpsTrigger: {}, + }, + v1httpPreserve: { + platform: "gcfv1", + entryPoint: "v1httpPreserve", + httpsTrigger: {}, + }, + v2http: { + platform: "gcfv2", + entryPoint: "v2http", + labels: {}, + httpsTrigger: {}, + }, + }, + requiredAPIs: [], + specVersion: "v1alpha1", + }, + }, ]; for (const tc of testcases) { diff --git a/spec/fixtures.ts b/spec/fixtures.ts index a21ce33c4..ddc2084fd 100644 --- a/spec/fixtures.ts +++ b/spec/fixtures.ts @@ -22,7 +22,7 @@ import { ManifestEndpoint } from "../src/runtime/manifest"; import { RESET_VALUE } from "../src/common/options"; -export const MINIMAL_ENDPOINT: Partial = { +export const MINIMAL_V2_ENDPOINT: ManifestEndpoint = { availableMemoryMb: RESET_VALUE, concurrency: RESET_VALUE, ingressSettings: RESET_VALUE, @@ -32,3 +32,33 @@ export const MINIMAL_ENDPOINT: Partial = { timeoutSeconds: RESET_VALUE, vpc: RESET_VALUE, }; + +export const MINIMAL_V1_ENDPOINT: ManifestEndpoint = { + availableMemoryMb: RESET_VALUE, + ingressSettings: RESET_VALUE, + maxInstances: RESET_VALUE, + minInstances: RESET_VALUE, + serviceAccountEmail: RESET_VALUE, + timeoutSeconds: RESET_VALUE, + vpc: RESET_VALUE, +}; + +export const FULL_ENDPOINT: ManifestEndpoint = { + region: ["us-west1"], + availableMemoryMb: 512, + timeoutSeconds: 60, + minInstances: 1, + maxInstances: 3, + concurrency: 20, + vpc: { + connector: "aConnector", + egressSettings: "ALL_TRAFFIC", + }, + serviceAccountEmail: "root@", + ingressSettings: "ALLOW_ALL", + cpu: "gcf_gen1", + labels: { + hello: "world", + }, + secretEnvironmentVariables: [{ key: "MY_SECRET" }], +}; diff --git a/spec/runtime/loader.spec.ts b/spec/runtime/loader.spec.ts index 906d1da4c..551ab2f70 100644 --- a/spec/runtime/loader.spec.ts +++ b/spec/runtime/loader.spec.ts @@ -5,6 +5,8 @@ import * as functions from "../../src/v1"; import * as loader from "../../src/runtime/loader"; import { ManifestEndpoint, ManifestRequiredAPI, ManifestStack } from "../../src/runtime/manifest"; import { clearParams } from "../../src/params"; +import { MINIMAL_V1_ENDPOINT, MINIMAL_V2_ENDPOINT } from "../fixtures"; +import { MINIMAL_SCHEDULE_TRIGGER, MINIMIAL_TASK_QUEUE_TRIGGER } from "../v1/providers/fixtures"; describe("extractStack", () => { const httpFn = functions.https.onRequest(() => undefined); @@ -32,8 +34,16 @@ describe("extractStack", () => { loader.extractStack(module, endpoints, requiredAPIs); expect(endpoints).to.be.deep.equal({ - http: { entryPoint: "http", ...httpEndpoint }, - callable: { entryPoint: "callable", ...callableEndpoint }, + http: { + ...MINIMAL_V1_ENDPOINT, + entryPoint: "http", + ...httpEndpoint, + }, + callable: { + ...MINIMAL_V1_ENDPOINT, + entryPoint: "callable", + ...callableEndpoint, + }, }); expect(requiredAPIs).to.be.empty; @@ -51,9 +61,10 @@ describe("extractStack", () => { expect(endpoints).to.be.deep.equal({ taskq: { + ...MINIMAL_V1_ENDPOINT, entryPoint: "taskq", platform: "gcfv1", - taskQueueTrigger: {}, + taskQueueTrigger: MINIMIAL_TASK_QUEUE_TRIGGER, }, }); @@ -80,10 +91,12 @@ describe("extractStack", () => { expect(endpoints).to.be.deep.equal({ fn1: { + ...MINIMAL_V1_ENDPOINT, entryPoint: "fn1", ...httpEndpoint, }, "g1-fn2": { + ...MINIMAL_V1_ENDPOINT, entryPoint: "g1.fn2", ...httpEndpoint, }, @@ -116,6 +129,7 @@ describe("extractStack", () => { expect(endpoints).to.be.deep.equal({ fn: { + ...MINIMAL_V1_ENDPOINT, entryPoint: "fn", platform: "gcfv1", eventTrigger: { @@ -142,11 +156,12 @@ describe("extractStack", () => { expect(endpoints).to.be.deep.equal({ scheduled: { + ...MINIMAL_V1_ENDPOINT, entryPoint: "scheduled", platform: "gcfv1", // TODO: This label should not exist? labels: {}, - scheduleTrigger: { schedule: "every 5 minutes" }, + scheduleTrigger: { ...MINIMAL_SCHEDULE_TRIGGER, schedule: "every 5 minutes" }, }, }); @@ -217,23 +232,27 @@ describe("loadStack", () => { const expected: ManifestStack = { endpoints: { v1http: { + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", entryPoint: "v1http", httpsTrigger: {}, }, v1callable: { + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", entryPoint: "v1callable", labels: {}, callableTrigger: {}, }, v2http: { + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", entryPoint: "v2http", labels: {}, httpsTrigger: {}, }, v2callable: { + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", entryPoint: "v2callable", labels: {}, @@ -293,11 +312,13 @@ describe("loadStack", () => { endpoints: { ...expected.endpoints, "g1-groupedhttp": { + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", entryPoint: "g1.groupedhttp", httpsTrigger: {}, }, "g1-groupedcallable": { + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", entryPoint: "g1.groupedcallable", labels: {}, diff --git a/spec/v1/cloud-functions.spec.ts b/spec/v1/cloud-functions.spec.ts index 3b228561c..f68269030 100644 --- a/spec/v1/cloud-functions.spec.ts +++ b/spec/v1/cloud-functions.spec.ts @@ -22,7 +22,14 @@ import { expect } from "chai"; -import { Event, EventContext, makeCloudFunction, MakeCloudFunctionArgs } from "../../src/v1"; +import { + Event, + EventContext, + makeCloudFunction, + MakeCloudFunctionArgs, + RESET_VALUE, +} from "../../src/v1"; +import { MINIMAL_V1_ENDPOINT } from "../fixtures"; describe("makeCloudFunction", () => { const cloudFunctionArgs: MakeCloudFunctionArgs = { @@ -44,6 +51,7 @@ describe("makeCloudFunction", () => { }); expect(cf.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", eventTrigger: { eventType: "mock.provider.mock.event", @@ -60,6 +68,7 @@ describe("makeCloudFunction", () => { const cf = makeCloudFunction(cloudFunctionArgs); expect(cf.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", eventTrigger: { eventType: "providers/provider/eventTypes/event", @@ -89,6 +98,7 @@ describe("makeCloudFunction", () => { }); expect(cf.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", timeoutSeconds: 10, region: ["us-central1"], @@ -117,6 +127,7 @@ describe("makeCloudFunction", () => { }); expect(cf.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", eventTrigger: { eventType: "mock.provider.mock.event", @@ -146,8 +157,18 @@ describe("makeCloudFunction", () => { }, }); expect(cf.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", - scheduleTrigger: schedule, + scheduleTrigger: { + ...schedule, + retryConfig: { + ...schedule.retryConfig, + maxBackoffDuration: RESET_VALUE, + maxDoublings: RESET_VALUE, + maxRetryDuration: RESET_VALUE, + minBackoffDuration: RESET_VALUE, + }, + }, labels: {}, }); }); diff --git a/spec/v1/function-builder.spec.ts b/spec/v1/function-builder.spec.ts index 325eb9b6e..f1e3e1189 100644 --- a/spec/v1/function-builder.spec.ts +++ b/spec/v1/function-builder.spec.ts @@ -23,6 +23,7 @@ import { expect } from "chai"; import * as functions from "../../src/v1"; +import { ResetValue } from "../../src/common/options"; describe("FunctionBuilder", () => { before(() => { @@ -225,7 +226,11 @@ describe("FunctionBuilder", () => { .auth.user() .onCreate((user) => user); - expect(fn.__endpoint.vpc.connector).to.equal("test-connector"); + if (!(fn.__endpoint.vpc instanceof ResetValue)) { + expect(fn.__endpoint.vpc.connector).to.equal("test-connector"); + } else { + expect.fail("__endpoint.vpc unexpectedly set to RESET_VALUE"); + } }); it("should allow a vpcConnectorEgressSettings to be set", () => { @@ -237,7 +242,11 @@ describe("FunctionBuilder", () => { .auth.user() .onCreate((user) => user); - expect(fn.__endpoint.vpc.egressSettings).to.equal("PRIVATE_RANGES_ONLY"); + if (!(fn.__endpoint.vpc instanceof ResetValue)) { + expect(fn.__endpoint.vpc.egressSettings).to.equal("PRIVATE_RANGES_ONLY"); + } else { + expect.fail("__endpoint.vpc unexpectedly set to RESET_VALUE"); + } }); it("should throw an error if user chooses an invalid vpcConnectorEgressSettings", () => { diff --git a/spec/v1/providers/analytics.spec.ts b/spec/v1/providers/analytics.spec.ts index ae46a92bc..d7172360a 100644 --- a/spec/v1/providers/analytics.spec.ts +++ b/spec/v1/providers/analytics.spec.ts @@ -26,6 +26,7 @@ import * as functions from "../../../src/v1"; import { Event } from "../../../src/v1/cloud-functions"; import * as analytics from "../../../src/v1/providers/analytics"; import * as analyticsSpecInput from "./analytics.spec.input"; +import { MINIMAL_V1_ENDPOINT } from "../../fixtures"; describe("Analytics Functions", () => { describe("EventBuilder", () => { @@ -57,6 +58,7 @@ describe("Analytics Functions", () => { const cloudFunction = analytics.event("first_open").onLog(() => null); expect(cloudFunction.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", eventTrigger: { eventFilters: { diff --git a/spec/v1/providers/auth.spec.ts b/spec/v1/providers/auth.spec.ts index 535e843b8..b9604c37a 100644 --- a/spec/v1/providers/auth.spec.ts +++ b/spec/v1/providers/auth.spec.ts @@ -25,6 +25,7 @@ import { UserRecord } from "../../../src/common/providers/identity"; import * as functions from "../../../src/v1"; import { CloudFunction, Event } from "../../../src/v1/cloud-functions"; import * as auth from "../../../src/v1/providers/auth"; +import { MINIMAL_V1_ENDPOINT } from "../../fixtures"; describe("Auth Functions", () => { const event: Event = { @@ -48,6 +49,7 @@ describe("Auth Functions", () => { describe("AuthBuilder", () => { function expectedEndpoint(project: string, eventType: string) { return { + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", eventTrigger: { eventFilters: { @@ -114,6 +116,7 @@ describe("Auth Functions", () => { const fn = auth.user().beforeCreate(() => Promise.resolve()); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", labels: {}, blockingTrigger: { @@ -149,6 +152,7 @@ describe("Auth Functions", () => { .beforeCreate(() => Promise.resolve()); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", labels: {}, region: ["us-east1"], @@ -177,6 +181,7 @@ describe("Auth Functions", () => { const fn = auth.user().beforeSignIn(() => Promise.resolve()); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", labels: {}, blockingTrigger: { @@ -212,6 +217,7 @@ describe("Auth Functions", () => { .beforeSignIn(() => Promise.resolve()); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", labels: {}, region: ["us-east1"], diff --git a/spec/v1/providers/database.spec.ts b/spec/v1/providers/database.spec.ts index a8c3a4eda..2d1368d59 100644 --- a/spec/v1/providers/database.spec.ts +++ b/spec/v1/providers/database.spec.ts @@ -27,6 +27,7 @@ import { applyChange } from "../../../src/common/utilities/utils"; import * as functions from "../../../src/v1"; import * as database from "../../../src/v1/providers/database"; import { expectType } from "../../common/metaprogramming"; +import { MINIMAL_V1_ENDPOINT } from "../../fixtures"; describe("Database Functions", () => { describe("DatabaseBuilder", () => { @@ -34,6 +35,7 @@ describe("Database Functions", () => { function expectedEndpoint(resource: string, eventType: string) { return { + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", eventTrigger: { eventFilters: { diff --git a/spec/v1/providers/firestore.spec.ts b/spec/v1/providers/firestore.spec.ts index 68d78d81a..1c66ec31b 100644 --- a/spec/v1/providers/firestore.spec.ts +++ b/spec/v1/providers/firestore.spec.ts @@ -26,6 +26,7 @@ import { Timestamp } from "firebase-admin/firestore"; import * as functions from "../../../src/v1"; import * as firestore from "../../../src/v1/providers/firestore"; import { expectType } from "../../common/metaprogramming"; +import { MINIMAL_V1_ENDPOINT } from "../../fixtures"; describe("Firestore Functions", () => { function constructValue(fields: any) { @@ -93,6 +94,7 @@ describe("Firestore Functions", () => { describe("document builders and event types", () => { function expectedEndpoint(resource: string, eventType: string) { return { + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", eventTrigger: { eventFilters: { diff --git a/spec/v1/providers/fixtures.ts b/spec/v1/providers/fixtures.ts index e69de29bb..e047ba07f 100644 --- a/spec/v1/providers/fixtures.ts +++ b/spec/v1/providers/fixtures.ts @@ -0,0 +1,50 @@ +// The MIT License (MIT) +// +// Copyright (c) 2022 Firebase +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +import { ManifestEndpoint } from "../../../src/runtime/manifest"; +import * as functions from "../../../src/v1"; +import * as options from "../../../src/v2/options"; + +export const MINIMIAL_TASK_QUEUE_TRIGGER: ManifestEndpoint["taskQueueTrigger"] = { + rateLimits: { + maxConcurrentDispatches: functions.RESET_VALUE, + maxDispatchesPerSecond: functions.RESET_VALUE, + }, + retryConfig: { + maxAttempts: functions.RESET_VALUE, + maxBackoffSeconds: functions.RESET_VALUE, + maxDoublings: functions.RESET_VALUE, + maxRetrySeconds: functions.RESET_VALUE, + minBackoffSeconds: functions.RESET_VALUE, + }, +}; + +export const MINIMAL_SCHEDULE_TRIGGER: ManifestEndpoint["scheduleTrigger"] = { + schedule: "", + timeZone: options.RESET_VALUE, + retryConfig: { + retryCount: options.RESET_VALUE, + maxRetryDuration: options.RESET_VALUE, + maxBackoffDuration: options.RESET_VALUE, + minBackoffDuration: options.RESET_VALUE, + maxDoublings: options.RESET_VALUE, + }, +}; diff --git a/spec/v1/providers/https.spec.ts b/spec/v1/providers/https.spec.ts index a6589932c..7d06a15c3 100644 --- a/spec/v1/providers/https.spec.ts +++ b/spec/v1/providers/https.spec.ts @@ -26,6 +26,7 @@ import * as functions from "../../../src/v1"; import * as https from "../../../src/v1/providers/https"; import { expectedResponseHeaders, MockRequest } from "../../fixtures/mockrequest"; import { runHandler } from "../../helper"; +import { MINIMAL_V1_ENDPOINT } from "../../fixtures"; describe("CloudHttpsBuilder", () => { describe("#onRequest", () => { @@ -34,6 +35,7 @@ describe("CloudHttpsBuilder", () => { resp.send(200); }); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", httpsTrigger: {}, }); @@ -64,6 +66,7 @@ describe("#onCall", () => { }); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", callableTrigger: {}, labels: {}, diff --git a/spec/v1/providers/pubsub.spec.ts b/spec/v1/providers/pubsub.spec.ts index 201fe2f1f..573ac0f1c 100644 --- a/spec/v1/providers/pubsub.spec.ts +++ b/spec/v1/providers/pubsub.spec.ts @@ -21,7 +21,10 @@ // SOFTWARE. import { expect } from "chai"; -import { Event } from "../../../src/v1"; + +import { Event, RESET_VALUE } from "../../../src/v1"; +import { MINIMAL_V1_ENDPOINT } from "../../fixtures"; +import { MINIMAL_SCHEDULE_TRIGGER } from "./fixtures"; import * as functions from "../../../src/v1"; import * as pubsub from "../../../src/v1/providers/pubsub"; @@ -91,6 +94,7 @@ describe("Pubsub Functions", () => { const result = pubsub.topic("toppy").onPublish(() => null); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", eventTrigger: { eventType: "google.pubsub.topic.publish", @@ -148,6 +152,7 @@ describe("Pubsub Functions", () => { const result = pubsub.schedule("every 5 minutes").onRun(() => null); expect(result.__endpoint.scheduleTrigger).to.deep.equal({ + ...MINIMAL_SCHEDULE_TRIGGER, schedule: "every 5 minutes", }); }); @@ -159,6 +164,7 @@ describe("Pubsub Functions", () => { .onRun(() => null); expect(result.__endpoint.scheduleTrigger).to.deep.equal({ + ...MINIMAL_SCHEDULE_TRIGGER, schedule: "every 5 minutes", timeZone: "America/New_York", }); @@ -178,6 +184,7 @@ describe("Pubsub Functions", () => { .onRun(() => null); expect(result.__endpoint.scheduleTrigger).to.deep.equal({ + ...MINIMAL_SCHEDULE_TRIGGER, schedule: "every 5 minutes", retryConfig, }); @@ -202,6 +209,7 @@ describe("Pubsub Functions", () => { .onRun(() => null); expect(result.__endpoint.scheduleTrigger).to.deep.equal({ + ...MINIMAL_SCHEDULE_TRIGGER, schedule: "every 5 minutes", retryConfig, timeZone: "America/New_York", @@ -221,6 +229,7 @@ describe("Pubsub Functions", () => { .onRun(() => null); expect(result.__endpoint.scheduleTrigger).to.deep.equal({ + ...MINIMAL_SCHEDULE_TRIGGER, schedule: "every 5 minutes", }); expect(result.__endpoint.region).to.deep.equal(["us-east1"]); @@ -240,6 +249,7 @@ describe("Pubsub Functions", () => { .onRun(() => null); expect(result.__endpoint.scheduleTrigger).to.deep.equal({ + ...MINIMAL_SCHEDULE_TRIGGER, schedule: "every 5 minutes", timeZone: "America/New_York", }); @@ -267,7 +277,9 @@ describe("Pubsub Functions", () => { .onRun(() => null); expect(result.__endpoint.scheduleTrigger).to.deep.equal({ + ...MINIMAL_SCHEDULE_TRIGGER, schedule: "every 5 minutes", + timeZone: RESET_VALUE, retryConfig, }); expect(result.__endpoint.region).to.deep.equal(["us-east1"]); @@ -295,6 +307,7 @@ describe("Pubsub Functions", () => { .onRun(() => null); expect(result.__endpoint.scheduleTrigger).to.deep.equal({ + ...MINIMAL_SCHEDULE_TRIGGER, schedule: "every 5 minutes", timeZone: "America/New_York", retryConfig, diff --git a/spec/v1/providers/remoteConfig.spec.ts b/spec/v1/providers/remoteConfig.spec.ts index 9b86ca311..45d13bb32 100644 --- a/spec/v1/providers/remoteConfig.spec.ts +++ b/spec/v1/providers/remoteConfig.spec.ts @@ -24,6 +24,7 @@ import { expect } from "chai"; import * as functions from "../../../src/v1"; import { CloudFunction, Event } from "../../../src/v1/cloud-functions"; import * as remoteConfig from "../../../src/v1/providers/remoteConfig"; +import { MINIMAL_V1_ENDPOINT } from "../../fixtures"; describe("RemoteConfig Functions", () => { function constructVersion() { @@ -53,6 +54,7 @@ describe("RemoteConfig Functions", () => { const cloudFunction = remoteConfig.onUpdate(() => null); expect(cloudFunction.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", eventTrigger: { eventType: "google.firebase.remoteconfig.update", diff --git a/spec/v1/providers/storage.spec.ts b/spec/v1/providers/storage.spec.ts index fe65070e0..0055e8769 100644 --- a/spec/v1/providers/storage.spec.ts +++ b/spec/v1/providers/storage.spec.ts @@ -21,15 +21,17 @@ // SOFTWARE. import { expect } from "chai"; -import * as config from "../../../src/common/config"; import { Event } from "../../../src/v1"; +import * as config from "../../../src/common/config"; import * as functions from "../../../src/v1"; import * as storage from "../../../src/v1/providers/storage"; +import { MINIMAL_V1_ENDPOINT } from "../../fixtures"; describe("Storage Functions", () => { describe("ObjectBuilder", () => { function expectedEndpoint(bucket: string, eventType: string) { return { + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", eventTrigger: { eventFilters: { diff --git a/spec/v1/providers/tasks.spec.ts b/spec/v1/providers/tasks.spec.ts index 785d5a208..ec9e6d318 100644 --- a/spec/v1/providers/tasks.spec.ts +++ b/spec/v1/providers/tasks.spec.ts @@ -26,6 +26,8 @@ import * as functions from "../../../src/v1"; import { taskQueue } from "../../../src/v1/providers/tasks"; import { MockRequest } from "../../fixtures/mockrequest"; import { runHandler } from "../../helper"; +import { MINIMAL_V1_ENDPOINT } from "../../fixtures"; +import { MINIMIAL_TASK_QUEUE_TRIGGER } from "./fixtures"; describe("#onDispatch", () => { it("should return a trigger/endpoint with appropriate values", () => { @@ -45,6 +47,7 @@ describe("#onDispatch", () => { }).onDispatch(() => undefined); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", taskQueueTrigger: { rateLimits: { @@ -74,11 +77,13 @@ describe("#onDispatch", () => { .onDispatch(() => null); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", region: ["us-east1"], availableMemoryMb: 256, timeoutSeconds: 90, taskQueueTrigger: { + ...MINIMIAL_TASK_QUEUE_TRIGGER, retryConfig: { maxAttempts: 5, }, diff --git a/spec/v1/providers/testLab.spec.ts b/spec/v1/providers/testLab.spec.ts index e19f79cae..6aaccad2e 100644 --- a/spec/v1/providers/testLab.spec.ts +++ b/spec/v1/providers/testLab.spec.ts @@ -23,6 +23,7 @@ import { expect } from "chai"; import * as testLab from "../../../src/v1/providers/testLab"; +import { MINIMAL_V1_ENDPOINT } from "../../fixtures"; describe("Test Lab Functions", () => { describe("#onComplete", () => { @@ -39,6 +40,7 @@ describe("Test Lab Functions", () => { const func = testLab.testMatrix().onComplete(() => null); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V1_ENDPOINT, platform: "gcfv1", eventTrigger: { eventType: "google.testing.testMatrix.complete", diff --git a/spec/v2/providers/alerts/alerts.spec.ts b/spec/v2/providers/alerts/alerts.spec.ts index 5daeebdac..4476e121e 100644 --- a/spec/v2/providers/alerts/alerts.spec.ts +++ b/spec/v2/providers/alerts/alerts.spec.ts @@ -2,7 +2,8 @@ import { expect } from "chai"; import { CloudEvent } from "../../../../src/v2"; import * as options from "../../../../src/v2/options"; import * as alerts from "../../../../src/v2/providers/alerts"; -import { FULL_ENDPOINT, FULL_OPTIONS } from "../fixtures"; +import { FULL_OPTIONS } from "../fixtures"; +import { FULL_ENDPOINT, MINIMAL_V2_ENDPOINT } from "../../../fixtures"; const ALERT_TYPE = "new-alert-type"; const APPID = "123456789"; @@ -22,6 +23,7 @@ describe("alerts", () => { const result = alerts.onAlertPublished(ALERT_TYPE, () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -44,6 +46,7 @@ describe("alerts", () => { expect(result.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: ALERT_APP_EVENT_FILTER, @@ -73,6 +76,7 @@ describe("alerts", () => { it("should define the endpoint without appId and opts", () => { expect(alerts.getEndpointAnnotation({}, ALERT_TYPE)).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -86,6 +90,7 @@ describe("alerts", () => { it("should define a complex endpoint without appId", () => { expect(alerts.getEndpointAnnotation({ ...FULL_OPTIONS }, ALERT_TYPE)).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: ALERT_EVENT_FILTER, @@ -97,6 +102,7 @@ describe("alerts", () => { it("should define a complex endpoint", () => { expect(alerts.getEndpointAnnotation({ ...FULL_OPTIONS }, ALERT_TYPE, APPID)).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: ALERT_APP_EVENT_FILTER, @@ -117,6 +123,7 @@ describe("alerts", () => { }; expect(alerts.getEndpointAnnotation(specificOpts, ALERT_TYPE, APPID)).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, concurrency: 20, diff --git a/spec/v2/providers/alerts/appDistribution.spec.ts b/spec/v2/providers/alerts/appDistribution.spec.ts index e24e4379a..7e2b7d0c6 100644 --- a/spec/v2/providers/alerts/appDistribution.spec.ts +++ b/spec/v2/providers/alerts/appDistribution.spec.ts @@ -1,7 +1,8 @@ import { expect } from "chai"; import * as alerts from "../../../../src/v2/providers/alerts"; import * as appDistribution from "../../../../src/v2/providers/alerts/appDistribution"; -import { FULL_ENDPOINT, FULL_OPTIONS } from "../fixtures"; +import { FULL_OPTIONS } from "../fixtures"; +import { FULL_ENDPOINT, MINIMAL_V2_ENDPOINT } from "../../../fixtures"; const APPID = "123456789"; const myHandler = () => 42; @@ -16,6 +17,7 @@ describe("appDistribution", () => { const func = appDistribution.onNewTesterIosDevicePublished(APPID, myHandler); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -34,6 +36,7 @@ describe("appDistribution", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: { @@ -52,6 +55,7 @@ describe("appDistribution", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: { @@ -67,6 +71,7 @@ describe("appDistribution", () => { const func = appDistribution.onNewTesterIosDevicePublished(myHandler); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -93,6 +98,7 @@ describe("appDistribution", () => { const func = appDistribution.onInAppFeedbackPublished(APPID, myHandler); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -111,6 +117,7 @@ describe("appDistribution", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: { @@ -129,6 +136,7 @@ describe("appDistribution", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: { @@ -144,6 +152,7 @@ describe("appDistribution", () => { const func = appDistribution.onInAppFeedbackPublished(myHandler); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { diff --git a/spec/v2/providers/alerts/billing.spec.ts b/spec/v2/providers/alerts/billing.spec.ts index b1a0fb887..d4be3403d 100644 --- a/spec/v2/providers/alerts/billing.spec.ts +++ b/spec/v2/providers/alerts/billing.spec.ts @@ -1,7 +1,8 @@ import { expect } from "chai"; import * as alerts from "../../../../src/v2/providers/alerts"; import * as billing from "../../../../src/v2/providers/alerts/billing"; -import { FULL_ENDPOINT, FULL_OPTIONS } from "../fixtures"; +import { FULL_OPTIONS } from "../fixtures"; +import { FULL_ENDPOINT, MINIMAL_V2_ENDPOINT } from "../../../fixtures"; const ALERT_TYPE = "new-alert-type"; const myHandler = () => 42; @@ -12,6 +13,7 @@ describe("billing", () => { const func = billing.onPlanUpdatePublished(myHandler); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -29,6 +31,7 @@ describe("billing", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: { @@ -45,6 +48,7 @@ describe("billing", () => { const func = billing.onPlanAutomatedUpdatePublished(myHandler); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -62,6 +66,7 @@ describe("billing", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: { @@ -78,6 +83,7 @@ describe("billing", () => { const func = billing.onOperation(ALERT_TYPE, myHandler, undefined); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -95,6 +101,7 @@ describe("billing", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: { diff --git a/spec/v2/providers/alerts/crashlytics.spec.ts b/spec/v2/providers/alerts/crashlytics.spec.ts index b8b62ccb4..fd4984b76 100644 --- a/spec/v2/providers/alerts/crashlytics.spec.ts +++ b/spec/v2/providers/alerts/crashlytics.spec.ts @@ -1,7 +1,8 @@ import { expect } from "chai"; import * as alerts from "../../../../src/v2/providers/alerts"; import * as crashlytics from "../../../../src/v2/providers/alerts/crashlytics"; -import { FULL_ENDPOINT, FULL_OPTIONS } from "../fixtures"; +import { FULL_OPTIONS } from "../fixtures"; +import { FULL_ENDPOINT, MINIMAL_V2_ENDPOINT } from "../../../fixtures"; const ALERT_TYPE = "new-alert-type"; const APPID = "123456789"; @@ -50,6 +51,7 @@ describe("crashlytics", () => { const func = crashlytics[method](myHandler); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -64,6 +66,7 @@ describe("crashlytics", () => { const func = crashlytics[method](APPID, myHandler); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -79,6 +82,7 @@ describe("crashlytics", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: ALERT_EVENT_FILTER, @@ -92,6 +96,7 @@ describe("crashlytics", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: ALERT_APP_EVENT_FILTER, @@ -116,6 +121,7 @@ describe("crashlytics", () => { const func = crashlytics.onOperation(ALERT_TYPE, myHandler, undefined); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -130,6 +136,7 @@ describe("crashlytics", () => { const func = crashlytics.onOperation(ALERT_TYPE, APPID, myHandler); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -145,6 +152,7 @@ describe("crashlytics", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: ALERT_EVENT_FILTER, @@ -162,6 +170,7 @@ describe("crashlytics", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: ALERT_APP_EVENT_FILTER, diff --git a/spec/v2/providers/alerts/performance.spec.ts b/spec/v2/providers/alerts/performance.spec.ts index 6766dd29d..667aa7ba5 100644 --- a/spec/v2/providers/alerts/performance.spec.ts +++ b/spec/v2/providers/alerts/performance.spec.ts @@ -1,7 +1,8 @@ import { expect } from "chai"; import * as alerts from "../../../../src/v2/providers/alerts"; import * as performance from "../../../../src/v2/providers/alerts/performance"; -import { FULL_ENDPOINT, FULL_OPTIONS } from "../fixtures"; +import { FULL_OPTIONS } from "../fixtures"; +import { FULL_ENDPOINT, MINIMAL_V2_ENDPOINT } from "../../../fixtures"; const APPID = "123456789"; const myHandler = () => 42; @@ -16,6 +17,7 @@ describe("performance", () => { const func = performance.onThresholdAlertPublished(APPID, myHandler); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -34,6 +36,7 @@ describe("performance", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: { @@ -52,6 +55,7 @@ describe("performance", () => { expect(func.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { eventType: alerts.eventType, eventFilters: { @@ -67,6 +71,7 @@ describe("performance", () => { const func = performance.onThresholdAlertPublished(myHandler); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { diff --git a/spec/v2/providers/database.spec.ts b/spec/v2/providers/database.spec.ts index aed3b44f1..acd87644d 100644 --- a/spec/v2/providers/database.spec.ts +++ b/spec/v2/providers/database.spec.ts @@ -24,6 +24,7 @@ import { expect } from "chai"; import { PathPattern } from "../../../src/common/utilities/path-pattern"; import * as database from "../../../src/v2/providers/database"; import { expectType } from "../../common/metaprogramming"; +import { MINIMAL_V2_ENDPOINT } from "../../fixtures"; const RAW_RTDB_EVENT: database.RawRTDBCloudEvent = { data: { @@ -157,6 +158,7 @@ describe("database", () => { ); expect(ep).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: { 1: "2", @@ -186,6 +188,7 @@ describe("database", () => { ); expect(ep).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: { 1: "2", @@ -210,6 +213,7 @@ describe("database", () => { const func = database.onChangedOperation(database.writtenEventType, "/foo/{bar}/", () => 2); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -228,6 +232,7 @@ describe("database", () => { const func = database.onChangedOperation(database.updatedEventType, "/foo/{bar}/", () => 2); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -256,6 +261,7 @@ describe("database", () => { ); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", cpu: "gcf_gen1", minInstances: 2, @@ -280,6 +286,7 @@ describe("database", () => { const func = database.onOperation(database.createdEventType, "/foo/{bar}/", () => 2); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -298,6 +305,7 @@ describe("database", () => { const func = database.onOperation(database.deletedEventType, "/foo/{bar}/", () => 2); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -326,6 +334,7 @@ describe("database", () => { ); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", cpu: "gcf_gen1", minInstances: 2, @@ -352,6 +361,7 @@ describe("database", () => { }); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -381,6 +391,7 @@ describe("database", () => { ); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", cpu: "gcf_gen1", minInstances: 2, @@ -407,6 +418,7 @@ describe("database", () => { }); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -439,6 +451,7 @@ describe("database", () => { ); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", cpu: "gcf_gen1", minInstances: 2, @@ -465,6 +478,7 @@ describe("database", () => { }); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -494,6 +508,7 @@ describe("database", () => { ); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", cpu: "gcf_gen1", minInstances: 2, @@ -520,6 +535,7 @@ describe("database", () => { }); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -549,6 +565,7 @@ describe("database", () => { ); expect(func.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", cpu: "gcf_gen1", minInstances: 2, diff --git a/spec/v2/providers/eventarc.spec.ts b/spec/v2/providers/eventarc.spec.ts index 2cafb482a..feb42b458 100644 --- a/spec/v2/providers/eventarc.spec.ts +++ b/spec/v2/providers/eventarc.spec.ts @@ -23,7 +23,8 @@ import { expect } from "chai"; import * as options from "../../../src/v2/options"; import * as eventarc from "../../../src/v2/providers/eventarc"; -import { FULL_ENDPOINT, FULL_OPTIONS } from "./fixtures"; +import { FULL_OPTIONS } from "./fixtures"; +import { FULL_ENDPOINT, MINIMAL_V2_ENDPOINT } from "../../fixtures"; const ENDPOINT_EVENT_TRIGGER = { eventType: "event-type", @@ -46,6 +47,7 @@ describe("v2/eventarc", () => { const result = eventarc.onCustomEventPublished("event-type", () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -62,6 +64,7 @@ describe("v2/eventarc", () => { ); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -83,6 +86,7 @@ describe("v2/eventarc", () => { ); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -107,6 +111,7 @@ describe("v2/eventarc", () => { expect(result.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: { ...ENDPOINT_EVENT_TRIGGER, channel: "locations/us-west1/channels/my-channel", @@ -132,6 +137,7 @@ describe("v2/eventarc", () => { ); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", concurrency: 20, minInstances: 3, diff --git a/spec/v2/providers/fixtures.ts b/spec/v2/providers/fixtures.ts index b70835864..f2c5b60e6 100644 --- a/spec/v2/providers/fixtures.ts +++ b/spec/v2/providers/fixtures.ts @@ -1,4 +1,3 @@ -import { ManifestEndpoint } from "../../../src/runtime/manifest"; import * as options from "../../../src/v2/options"; export const FULL_OPTIONS: options.GlobalOptions = { @@ -18,24 +17,3 @@ export const FULL_OPTIONS: options.GlobalOptions = { }, secrets: ["MY_SECRET"], }; - -export const FULL_ENDPOINT: ManifestEndpoint = { - platform: "gcfv2", - region: ["us-west1"], - availableMemoryMb: 512, - timeoutSeconds: 60, - minInstances: 1, - maxInstances: 3, - concurrency: 20, - vpc: { - connector: "aConnector", - egressSettings: "ALL_TRAFFIC", - }, - serviceAccountEmail: "root@", - ingressSettings: "ALLOW_ALL", - cpu: "gcf_gen1", - labels: { - hello: "world", - }, - secretEnvironmentVariables: [{ key: "MY_SECRET" }], -}; diff --git a/spec/v2/providers/https.spec.ts b/spec/v2/providers/https.spec.ts index a1c22bf0e..eabf471fb 100644 --- a/spec/v2/providers/https.spec.ts +++ b/spec/v2/providers/https.spec.ts @@ -28,7 +28,8 @@ import * as options from "../../../src/v2/options"; import * as https from "../../../src/v2/providers/https"; import { expectedResponseHeaders, MockRequest } from "../../fixtures/mockrequest"; import { runHandler } from "../../helper"; -import { FULL_ENDPOINT, FULL_OPTIONS } from "./fixtures"; +import { FULL_OPTIONS } from "./fixtures"; +import { FULL_ENDPOINT, MINIMAL_V2_ENDPOINT } from "../../fixtures"; describe("onRequest", () => { beforeEach(() => { @@ -46,6 +47,7 @@ describe("onRequest", () => { }); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", httpsTrigger: {}, labels: {}, @@ -66,6 +68,7 @@ describe("onRequest", () => { expect(result.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", httpsTrigger: { invoker: ["service-account1@", "service-account2@"], }, @@ -93,6 +96,7 @@ describe("onRequest", () => { ); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", httpsTrigger: { invoker: ["private"], @@ -199,6 +203,7 @@ describe("onCall", () => { const result = https.onCall(() => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", callableTrigger: {}, labels: {}, @@ -210,6 +215,7 @@ describe("onCall", () => { expect(result.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", callableTrigger: {}, }); }); @@ -230,6 +236,7 @@ describe("onCall", () => { ); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", callableTrigger: {}, concurrency: 20, diff --git a/spec/v2/providers/identity.spec.ts b/spec/v2/providers/identity.spec.ts index 5576a0021..7559a4133 100644 --- a/spec/v2/providers/identity.spec.ts +++ b/spec/v2/providers/identity.spec.ts @@ -21,6 +21,7 @@ // SOFTWARE. import { expect } from "chai"; import * as identity from "../../../src/v2/providers/identity"; +import { MINIMAL_V2_ENDPOINT } from "../../fixtures"; const BEFORE_CREATE_TRIGGER = { eventType: "providers/cloud.auth/eventTypes/user.beforeCreate", @@ -53,6 +54,7 @@ describe("identity", () => { const fn = identity.beforeUserCreated(() => Promise.resolve()); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, blockingTrigger: BEFORE_CREATE_TRIGGER, @@ -69,6 +71,7 @@ describe("identity", () => { const fn = identity.beforeUserCreated(opts, () => Promise.resolve()); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, minInstances: 1, @@ -95,6 +98,7 @@ describe("identity", () => { const fn = identity.beforeUserSignedIn(() => Promise.resolve()); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, blockingTrigger: BEFORE_SIGN_IN_TRIGGER, @@ -111,6 +115,7 @@ describe("identity", () => { const fn = identity.beforeUserSignedIn(opts, () => Promise.resolve()); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, minInstances: 1, @@ -137,6 +142,7 @@ describe("identity", () => { const fn = identity.beforeOperation("beforeCreate", () => Promise.resolve(), undefined); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, blockingTrigger: BEFORE_CREATE_TRIGGER, @@ -153,6 +159,7 @@ describe("identity", () => { const fn = identity.beforeOperation("beforeSignIn", () => Promise.resolve(), undefined); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, blockingTrigger: BEFORE_SIGN_IN_TRIGGER, @@ -169,6 +176,7 @@ describe("identity", () => { const fn = identity.beforeOperation("beforeCreate", opts, () => Promise.resolve()); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, minInstances: 1, @@ -193,6 +201,7 @@ describe("identity", () => { const fn = identity.beforeOperation("beforeSignIn", opts, () => Promise.resolve()); expect(fn.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, minInstances: 1, diff --git a/spec/v2/providers/pubsub.spec.ts b/spec/v2/providers/pubsub.spec.ts index 865593fb0..396dbd406 100644 --- a/spec/v2/providers/pubsub.spec.ts +++ b/spec/v2/providers/pubsub.spec.ts @@ -1,9 +1,10 @@ import { expect } from "chai"; import { CloudEvent } from "../../../src/v2/core"; +import { FULL_OPTIONS } from "./fixtures"; +import { FULL_ENDPOINT, MINIMAL_V2_ENDPOINT } from "../../fixtures"; import * as options from "../../../src/v2/options"; import * as pubsub from "../../../src/v2/providers/pubsub"; -import { FULL_ENDPOINT, FULL_OPTIONS } from "./fixtures"; const EVENT_TRIGGER = { eventType: "google.cloud.pubsub.topic.v1.messagePublished", @@ -32,6 +33,7 @@ describe("onMessagePublished", () => { const result = pubsub.onMessagePublished("topic", () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", eventTrigger: ENDPOINT_EVENT_TRIGGER, labels: {}, @@ -43,6 +45,7 @@ describe("onMessagePublished", () => { expect(result.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: ENDPOINT_EVENT_TRIGGER, }); }); @@ -64,6 +67,7 @@ describe("onMessagePublished", () => { ); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", concurrency: 20, minInstances: 3, @@ -85,6 +89,7 @@ describe("onMessagePublished", () => { ); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", minInstances: 3, region: ["us-west1"], diff --git a/spec/v2/providers/remoteConfig.spec.ts b/spec/v2/providers/remoteConfig.spec.ts index adcc0f009..5faf907ec 100644 --- a/spec/v2/providers/remoteConfig.spec.ts +++ b/spec/v2/providers/remoteConfig.spec.ts @@ -23,6 +23,7 @@ import { expect } from "chai"; import * as remoteConfig from "../../../src/v2/providers/remoteConfig"; import * as options from "../../../src/v2/options"; +import { MINIMAL_V2_ENDPOINT } from "../../fixtures"; describe("onConfigUpdated", () => { afterEach(() => { @@ -33,6 +34,7 @@ describe("onConfigUpdated", () => { const fn = remoteConfig.onConfigUpdated(() => 2); expect(fn.__endpoint).to.deep.eq({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -59,6 +61,7 @@ describe("onConfigUpdated", () => { ); expect(fn.__endpoint).to.deep.eq({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", availableMemoryMb: 512, region: ["us-central1"], diff --git a/spec/v2/providers/scheduler.spec.ts b/spec/v2/providers/scheduler.spec.ts index 5e29b1a6d..5ca9fb407 100644 --- a/spec/v2/providers/scheduler.spec.ts +++ b/spec/v2/providers/scheduler.spec.ts @@ -21,7 +21,22 @@ // SOFTWARE. import { expect } from "chai"; +import { ManifestEndpoint } from "../../../src/runtime/manifest"; +import * as options from "../../../src/v2/options"; import * as schedule from "../../../src/v2/providers/scheduler"; +import { MINIMAL_V2_ENDPOINT } from "../../fixtures"; + +const MINIMAL_SCHEDULE_TRIGGER: ManifestEndpoint["scheduleTrigger"] = { + schedule: "", + timeZone: options.RESET_VALUE, + retryConfig: { + retryCount: options.RESET_VALUE, + maxRetrySeconds: options.RESET_VALUE, + minBackoffSeconds: options.RESET_VALUE, + maxBackoffSeconds: options.RESET_VALUE, + maxDoublings: options.RESET_VALUE, + }, +}; describe("schedule", () => { describe("getOpts", () => { @@ -67,11 +82,12 @@ describe("schedule", () => { const schfn = schedule.onSchedule("* * * * *", () => console.log(1)); expect(schfn.__endpoint).to.deep.eq({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, scheduleTrigger: { + ...MINIMAL_SCHEDULE_TRIGGER, schedule: "* * * * *", - retryConfig: {}, }, }); expect(schfn.__requiredAPIs).to.deep.eq([ @@ -99,6 +115,7 @@ describe("schedule", () => { ); expect(schfn.__endpoint).to.deep.eq({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: { key: "val" }, region: ["us-central1"], diff --git a/spec/v2/providers/storage.spec.ts b/spec/v2/providers/storage.spec.ts index 4a2c7bb27..5a820ea7d 100644 --- a/spec/v2/providers/storage.spec.ts +++ b/spec/v2/providers/storage.spec.ts @@ -2,7 +2,8 @@ import { expect } from "chai"; import * as config from "../../../src/common/config"; import * as options from "../../../src/v2/options"; import * as storage from "../../../src/v2/providers/storage"; -import { FULL_ENDPOINT, FULL_OPTIONS } from "./fixtures"; +import { FULL_OPTIONS } from "./fixtures"; +import { FULL_ENDPOINT, MINIMAL_V2_ENDPOINT } from "../../fixtures"; const ENDPOINT_EVENT_TRIGGER = { eventType: "event-type", @@ -75,6 +76,7 @@ describe("v2/storage", () => { const result = storage.onOperation("event-type", "some-bucket", () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: ENDPOINT_EVENT_TRIGGER, @@ -87,6 +89,7 @@ describe("v2/storage", () => { const result = storage.onOperation("event-type", { region: "us-west1" }, () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -101,6 +104,7 @@ describe("v2/storage", () => { const result = storage.onOperation("event-type", { bucket: "some-bucket" }, () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: ENDPOINT_EVENT_TRIGGER, @@ -119,6 +123,7 @@ describe("v2/storage", () => { expect(result.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, + platform: "gcfv2", eventTrigger: ENDPOINT_EVENT_TRIGGER, }); }); @@ -141,6 +146,7 @@ describe("v2/storage", () => { ); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", concurrency: 20, minInstances: 3, @@ -167,6 +173,7 @@ describe("v2/storage", () => { const result = storage.onObjectArchived(() => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -180,6 +187,7 @@ describe("v2/storage", () => { const result = storage.onObjectArchived("my-bucket", () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -196,6 +204,7 @@ describe("v2/storage", () => { ); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -212,6 +221,7 @@ describe("v2/storage", () => { const result = storage.onObjectArchived({ region: "us-west1" }, () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -239,6 +249,7 @@ describe("v2/storage", () => { const result = storage.onObjectFinalized(() => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -252,6 +263,7 @@ describe("v2/storage", () => { const result = storage.onObjectFinalized("my-bucket", () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -268,6 +280,7 @@ describe("v2/storage", () => { ); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -284,6 +297,7 @@ describe("v2/storage", () => { const result = storage.onObjectFinalized({ region: "us-west1" }, () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -311,6 +325,7 @@ describe("v2/storage", () => { const result = storage.onObjectDeleted(() => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -324,6 +339,7 @@ describe("v2/storage", () => { const result = storage.onObjectDeleted("my-bucket", () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -337,6 +353,7 @@ describe("v2/storage", () => { const result = storage.onObjectDeleted({ bucket: "my-bucket", region: "us-west1" }, () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -353,6 +370,7 @@ describe("v2/storage", () => { const result = storage.onObjectDeleted({ region: "us-west1" }, () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -380,6 +398,7 @@ describe("v2/storage", () => { const result = storage.onObjectMetadataUpdated(() => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -393,6 +412,7 @@ describe("v2/storage", () => { const result = storage.onObjectMetadataUpdated("my-bucket", () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -409,6 +429,7 @@ describe("v2/storage", () => { ); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { @@ -425,6 +446,7 @@ describe("v2/storage", () => { const result = storage.onObjectMetadataUpdated({ region: "us-west1" }, () => 42); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", labels: {}, eventTrigger: { diff --git a/spec/v2/providers/tasks.spec.ts b/spec/v2/providers/tasks.spec.ts index f88c96c7a..8131a3725 100644 --- a/spec/v2/providers/tasks.spec.ts +++ b/spec/v2/providers/tasks.spec.ts @@ -22,11 +22,27 @@ import { expect } from "chai"; -import * as options from "../../../src/v2/options"; +import { ManifestEndpoint } from "../../../src/runtime/manifest"; import { onTaskDispatched, Request } from "../../../src/v2/providers/tasks"; import { MockRequest } from "../../fixtures/mockrequest"; import { runHandler } from "../../helper"; -import { FULL_ENDPOINT, FULL_OPTIONS } from "./fixtures"; +import { FULL_OPTIONS } from "./fixtures"; +import { FULL_ENDPOINT, MINIMAL_V2_ENDPOINT } from "../../fixtures"; +import * as options from "../../../src/v2/options"; + +const MINIMIAL_TASK_QUEUE_TRIGGER: ManifestEndpoint["taskQueueTrigger"] = { + rateLimits: { + maxConcurrentDispatches: options.RESET_VALUE, + maxDispatchesPerSecond: options.RESET_VALUE, + }, + retryConfig: { + maxAttempts: options.RESET_VALUE, + maxBackoffSeconds: options.RESET_VALUE, + maxDoublings: options.RESET_VALUE, + maxRetrySeconds: options.RESET_VALUE, + minBackoffSeconds: options.RESET_VALUE, + }, +}; describe("onTaskDispatched", () => { beforeEach(() => { @@ -42,9 +58,10 @@ describe("onTaskDispatched", () => { const result = onTaskDispatched(() => undefined); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", - taskQueueTrigger: {}, labels: {}, + taskQueueTrigger: MINIMIAL_TASK_QUEUE_TRIGGER, }); }); @@ -104,12 +121,13 @@ describe("onTaskDispatched", () => { ); expect(result.__endpoint).to.deep.equal({ + ...MINIMAL_V2_ENDPOINT, platform: "gcfv2", - taskQueueTrigger: {}, concurrency: 20, minInstances: 3, region: ["us-west1"], labels: {}, + taskQueueTrigger: MINIMIAL_TASK_QUEUE_TRIGGER, }); });