Skip to content

Commit

Permalink
Add CPU option. Rip out deprecated apiVersion (#1077)
Browse files Browse the repository at this point in the history
* Add CPU option. Rip out deprecated apiVersion

* Formatter

* PR feedback
  • Loading branch information
inlined committed Apr 15, 2022
1 parent 19d7d6e commit 78dae73
Show file tree
Hide file tree
Showing 33 changed files with 120 additions and 167 deletions.
8 changes: 4 additions & 4 deletions integration_test/functions/src/index.ts
@@ -1,9 +1,9 @@
import { PubSub } from '@google-cloud/pubsub';
import { Request, Response } from 'express';
import fetch from 'node-fetch';
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import * as fs from 'fs';
import fetch from 'node-fetch';

import * as v1 from './v1';
import * as v2 from './v2';
Expand All @@ -15,8 +15,8 @@ const getNumTests = (m: object): number => {
const numTests = getNumTests(v1) + getNumTests(v2);
export { v1, v2 };

import * as testLab from './v1/testLab-utils';
import { REGION } from './region';
import * as testLab from './v1/testLab-utils';

const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);
admin.initializeApp();
Expand Down Expand Up @@ -115,7 +115,7 @@ async function updateRemoteConfig(
}
}

function v1Tests(testId: string, accessToken: string): Promise<void>[] {
function v1Tests(testId: string, accessToken: string): Array<Promise<void>> {
return [
// A database write to trigger the Firebase Realtime Database tests.
admin
Expand Down Expand Up @@ -159,7 +159,7 @@ function v1Tests(testId: string, accessToken: string): Promise<void>[] {
];
}

function v2Tests(testId: string, accessToken: string): Promise<void>[] {
function v2Tests(testId: string, accessToken: string): Array<Promise<void>> {
return [
// Invoke a callable HTTPS trigger.
callV2HttpsTrigger('v2-callabletests', { foo: 'bar', testId }, accessToken),
Expand Down
2 changes: 1 addition & 1 deletion integration_test/functions/src/v1/auth-tests.ts
@@ -1,7 +1,7 @@
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import { expectEq, TestSuite } from '../testing';
import { REGION } from '../region';
import { expectEq, TestSuite } from '../testing';
import UserMetadata = admin.auth.UserRecord;

export const createUserTests: any = functions
Expand Down
2 changes: 1 addition & 1 deletion integration_test/functions/src/v1/database-tests.ts
@@ -1,7 +1,7 @@
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import { expectEq, expectMatches, TestSuite } from '../testing';
import { REGION } from '../region';
import { expectEq, expectMatches, TestSuite } from '../testing';
import DataSnapshot = admin.database.DataSnapshot;

const testIdFieldName = 'testId';
Expand Down
2 changes: 1 addition & 1 deletion integration_test/functions/src/v1/firestore-tests.ts
@@ -1,7 +1,7 @@
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import { expectDeepEq, expectEq, TestSuite } from '../testing';
import { REGION } from '../region';
import { expectDeepEq, expectEq, TestSuite } from '../testing';
import DocumentSnapshot = admin.firestore.DocumentSnapshot;

const testIdFieldName = 'documentId';
Expand Down
2 changes: 1 addition & 1 deletion integration_test/functions/src/v1/testLab-utils.ts
@@ -1,5 +1,5 @@
import fetch from 'node-fetch';
import * as admin from 'firebase-admin';
import fetch from 'node-fetch';

interface AndroidDevice {
androidModelId: string;
Expand Down
2 changes: 1 addition & 1 deletion integration_test/functions/src/v2/index.ts
@@ -1,5 +1,5 @@
import { REGION } from '../region';
import { setGlobalOptions } from 'firebase-functions/v2';
import { REGION } from '../region';
setGlobalOptions({ region: REGION });

export * from './https-tests';
14 changes: 8 additions & 6 deletions scripts/bin-test/test.ts
@@ -1,12 +1,12 @@
import * as path from 'path';
import * as subprocess from 'child_process';
import * as path from 'path';
import { promisify } from 'util';

import { expect } from 'chai';
import * as yaml from 'js-yaml';
import fetch from 'node-fetch';
import * as portfinder from 'portfinder';
import * as yaml from 'js-yaml';
import * as semver from 'semver';
import { expect } from 'chai';

const TIMEOUT_XL = 20_000;
const TIMEOUT_L = 10_000;
Expand Down Expand Up @@ -43,11 +43,11 @@ const BASE_STACK = {
specVersion: 'v1alpha1',
};

type Testcase = {
interface Testcase {
name: string;
modulePath: string;
expected: Record<string, any>;
};
}

async function retryUntil(
fn: () => Promise<boolean>,
Expand All @@ -66,7 +66,9 @@ async function retryUntil(
});
const retry = (async () => {
while (true) {
if (await fn()) break;
if (await fn()) {
break;
}
await sleep();
}
})();
Expand Down
18 changes: 9 additions & 9 deletions spec/common/providers/https.spec.ts
Expand Up @@ -3,12 +3,9 @@ import * as firebase from 'firebase-admin';
import * as sinon from 'sinon';

import { apps as appsNamespace } from '../../../src/apps';
import {
checkAppCheckContext,
checkAuthContext,
runHandler,
RunHandlerResult,
} from '../../helper';
import * as debug from '../../../src/common/debug';
import * as https from '../../../src/common/providers/https';
import * as mocks from '../../fixtures/credential/key.json';
import {
expectedResponseHeaders,
generateAppCheckToken,
Expand All @@ -19,9 +16,12 @@ import {
mockFetchPublicKeys,
mockRequest,
} from '../../fixtures/mockrequest';
import * as debug from '../../../src/common/debug';
import * as https from '../../../src/common/providers/https';
import * as mocks from '../../fixtures/credential/key.json';
import {
checkAppCheckContext,
checkAuthContext,
runHandler,
RunHandlerResult,
} from '../../helper';

/**
* A CallTest is a specification for a test of a callable function that
Expand Down
12 changes: 6 additions & 6 deletions spec/common/providers/identity.spec.ts
Expand Up @@ -20,11 +20,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import { expect } from 'chai';
import * as express from 'express';
import * as jwt from 'jsonwebtoken';
import * as sinon from 'sinon';
import * as identity from '../../../src/common/providers/identity';
import { expect } from 'chai';

const PROJECT = 'my-project';
const EVENT = 'EVENT_TYPE';
Expand Down Expand Up @@ -308,8 +308,8 @@ describe('identity', () => {
kid: '123456',
},
{
'123456': '7890',
'2468': '1357',
123456: '7890',
2468: '1357',
}
)
).to.eq('7890');
Expand Down Expand Up @@ -438,7 +438,7 @@ describe('identity', () => {
const decoded = {
aud: VALID_URL,
iss: `${identity.JWT_ISSUER}${PROJECT}`,
sub: sub,
sub,
event_type: EVENT,
} as identity.DecodedPayload;

Expand Down Expand Up @@ -515,8 +515,8 @@ describe('identity', () => {
let jwtVerifyStub: sinon.SinonStub;
const keysCache = {
publicKeys: {
'123456': '7890',
'2468': '1357',
123456: '7890',
2468: '1357',
},
publicKeysExpireAt: time + identity.INVALID_TOKEN_BUFFER + 10000,
};
Expand Down
18 changes: 9 additions & 9 deletions spec/common/providers/tasks.spec.ts
Expand Up @@ -23,20 +23,20 @@
import { expect } from 'chai';
import * as firebase from 'firebase-admin';

import { checkAuthContext, runHandler } from '../../helper';
import {
generateIdToken,
generateUnsignedIdToken,
mockRequest,
} from '../../fixtures/mockrequest';
import { apps as appsNamespace } from '../../../src/apps';
import * as https from '../../../src/common/providers/https';
import {
onDispatchHandler,
TaskContext,
Request,
TaskContext,
} from '../../../src/common/providers/tasks';
import { apps as appsNamespace } from '../../../src/apps';
import * as mocks from '../../fixtures/credential/key.json';
import * as https from '../../../src/common/providers/https';
import {
generateIdToken,
generateUnsignedIdToken,
mockRequest,
} from '../../fixtures/mockrequest';
import { checkAuthContext, runHandler } from '../../helper';

/** Represents a test case for a Task Queue Function */
interface TaskTest {
Expand Down
2 changes: 1 addition & 1 deletion spec/helper.ts
Expand Up @@ -20,8 +20,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import * as express from 'express';
import { expect } from 'chai';
import * as express from 'express';

import * as https from '../src/common/providers/https';
import * as tasks from '../src/common/providers/tasks';
Expand Down
8 changes: 4 additions & 4 deletions spec/runtime/loader.spec.ts
@@ -1,8 +1,8 @@
import * as path from 'path';
import { expect } from 'chai';
import * as path from 'path';

import * as loader from '../../src/runtime/loader';
import * as functions from '../../src/index';
import * as loader from '../../src/runtime/loader';
import {
ManifestEndpoint,
ManifestRequiredAPI,
Expand Down Expand Up @@ -246,11 +246,11 @@ describe('loadStack', () => {
specVersion: 'v1alpha1',
};

type Testcase = {
interface Testcase {
name: string;
modulePath: string;
expected: ManifestStack;
};
}
function runTests(tc: Testcase) {
it('loads stack given relative path', async () => {
await expect(loader.loadStack(tc.modulePath)).to.eventually.deep.equal(
Expand Down
19 changes: 2 additions & 17 deletions spec/v2/providers/eventarc.spec.ts
Expand Up @@ -23,7 +23,7 @@
import { expect } from 'chai';
import * as options from '../../../src/v2/options';
import * as eventarc from '../../../src/v2/providers/eventarc';
import { FULL_OPTIONS } from './fixtures';
import { FULL_ENDPOINT, FULL_OPTIONS } from './fixtures';

const ENDPOINT_EVENT_TRIGGER = {
eventType: 'event-type',
Expand Down Expand Up @@ -106,22 +106,7 @@ describe('v2/eventarc', () => {
);

expect(result.__endpoint).to.deep.equal({
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',
labels: {
hello: 'world',
},
...FULL_ENDPOINT,
eventTrigger: {
...ENDPOINT_EVENT_TRIGGER,
channel: 'locations/us-west1/channels/my-channel',
Expand Down
3 changes: 2 additions & 1 deletion spec/v2/providers/fixtures.ts
Expand Up @@ -11,13 +11,13 @@ export const FULL_OPTIONS: options.GlobalOptions = {
vpcConnectorEgressSettings: 'ALL_TRAFFIC',
serviceAccount: 'root@',
ingressSettings: 'ALLOW_ALL',
cpu: 'gcf_gen1',
labels: {
hello: 'world',
},
};

export const FULL_TRIGGER = {
apiVersion: 2,
platform: 'gcfv2',
regions: ['us-west1'],
availableMemoryMb: 512,
Expand Down Expand Up @@ -48,6 +48,7 @@ export const FULL_ENDPOINT = {
},
serviceAccountEmail: 'root@',
ingressSettings: 'ALLOW_ALL',
cpu: 'gcf_gen1',
labels: {
hello: 'world',
},
Expand Down
6 changes: 1 addition & 5 deletions spec/v2/providers/https.spec.ts
Expand Up @@ -28,8 +28,8 @@ import {
expectedResponseHeaders,
MockRequest,
} from '../../fixtures/mockrequest';
import { FULL_ENDPOINT, FULL_OPTIONS, FULL_TRIGGER } from './fixtures';
import { runHandler } from '../../helper';
import { FULL_ENDPOINT, FULL_OPTIONS, FULL_TRIGGER } from './fixtures';

describe('onRequest', () => {
beforeEach(() => {
Expand All @@ -47,7 +47,6 @@ describe('onRequest', () => {
});

expect(result.__trigger).to.deep.equal({
apiVersion: 2,
platform: 'gcfv2',
httpsTrigger: {
allowInsecure: false,
Expand Down Expand Up @@ -112,7 +111,6 @@ describe('onRequest', () => {
);

expect(result.__trigger).to.deep.equal({
apiVersion: 2,
platform: 'gcfv2',
httpsTrigger: {
allowInsecure: false,
Expand Down Expand Up @@ -199,7 +197,6 @@ describe('onCall', () => {
const result = https.onCall((request) => 42);

expect(result.__trigger).to.deep.equal({
apiVersion: 2,
platform: 'gcfv2',
httpsTrigger: {
allowInsecure: false,
Expand Down Expand Up @@ -252,7 +249,6 @@ describe('onCall', () => {
);

expect(result.__trigger).to.deep.equal({
apiVersion: 2,
platform: 'gcfv2',
httpsTrigger: {
allowInsecure: false,
Expand Down
3 changes: 0 additions & 3 deletions spec/v2/providers/pubsub.spec.ts
Expand Up @@ -32,7 +32,6 @@ describe('onMessagePublished', () => {
const result = pubsub.onMessagePublished('topic', () => 42);

expect(result.__trigger).to.deep.equal({
apiVersion: 2,
platform: 'gcfv2',
eventTrigger: EVENT_TRIGGER,
labels: {},
Expand Down Expand Up @@ -79,7 +78,6 @@ describe('onMessagePublished', () => {
);

expect(result.__trigger).to.deep.equal({
apiVersion: 2,
platform: 'gcfv2',
concurrency: 20,
minInstances: 3,
Expand Down Expand Up @@ -110,7 +108,6 @@ describe('onMessagePublished', () => {
);

expect(result.__trigger).to.deep.equal({
apiVersion: 2,
platform: 'gcfv2',
minInstances: 3,
regions: ['us-west1'],
Expand Down

0 comments on commit 78dae73

Please sign in to comment.