Skip to content

Fix broken test. #1254

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

Merged
merged 7 commits into from
Oct 5, 2022
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
18 changes: 18 additions & 0 deletions scripts/bin-test/sources/commonjs-preserve/index.js
Original file line number Diff line number Diff line change
@@ -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");
});
3 changes: 3 additions & 0 deletions scripts/bin-test/sources/commonjs-preserve/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "commonjs-preserve"
}
49 changes: 48 additions & 1 deletion scripts/bin-test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -82,7 +100,7 @@ async function startBin(
const getPort = promisify(portfinder.getPort) as () => Promise<number>;
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,
Expand Down Expand Up @@ -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: {},
Expand All @@ -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) {
Expand Down
32 changes: 31 additions & 1 deletion spec/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import { ManifestEndpoint } from "../src/runtime/manifest";
import { RESET_VALUE } from "../src/common/options";

export const MINIMAL_ENDPOINT: Partial<ManifestEndpoint> = {
export const MINIMAL_V2_ENDPOINT: ManifestEndpoint = {
availableMemoryMb: RESET_VALUE,
concurrency: RESET_VALUE,
ingressSettings: RESET_VALUE,
Expand All @@ -32,3 +32,33 @@ export const MINIMAL_ENDPOINT: Partial<ManifestEndpoint> = {
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" }],
};
29 changes: 25 additions & 4 deletions spec/runtime/loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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,
},
});

Expand All @@ -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,
},
Expand Down Expand Up @@ -116,6 +129,7 @@ describe("extractStack", () => {

expect(endpoints).to.be.deep.equal({
fn: {
...MINIMAL_V1_ENDPOINT,
entryPoint: "fn",
platform: "gcfv1",
eventTrigger: {
Expand All @@ -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" },
},
});

Expand Down Expand Up @@ -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: {},
Expand Down Expand Up @@ -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: {},
Expand Down
25 changes: 23 additions & 2 deletions spec/v1/cloud-functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = {
Expand All @@ -44,6 +51,7 @@ describe("makeCloudFunction", () => {
});

expect(cf.__endpoint).to.deep.equal({
...MINIMAL_V1_ENDPOINT,
platform: "gcfv1",
eventTrigger: {
eventType: "mock.provider.mock.event",
Expand All @@ -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",
Expand Down Expand Up @@ -89,6 +98,7 @@ describe("makeCloudFunction", () => {
});

expect(cf.__endpoint).to.deep.equal({
...MINIMAL_V1_ENDPOINT,
platform: "gcfv1",
timeoutSeconds: 10,
region: ["us-central1"],
Expand Down Expand Up @@ -117,6 +127,7 @@ describe("makeCloudFunction", () => {
});

expect(cf.__endpoint).to.deep.equal({
...MINIMAL_V1_ENDPOINT,
platform: "gcfv1",
eventTrigger: {
eventType: "mock.provider.mock.event",
Expand Down Expand Up @@ -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: {},
});
});
Expand Down
13 changes: 11 additions & 2 deletions spec/v1/function-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import { expect } from "chai";

import * as functions from "../../src/v1";
import { ResetValue } from "../../src/common/options";

describe("FunctionBuilder", () => {
before(() => {
Expand Down Expand Up @@ -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", () => {
Expand All @@ -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", () => {
Expand Down
Loading