Skip to content
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
11 changes: 7 additions & 4 deletions integration_test/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as functions from 'firebase-functions';
import * as https from 'https';
import * as admin from 'firebase-admin';
import { Request, Response } from 'express';
import * as fs from 'fs'
import * as fs from 'fs';

import * as PubSub from '@google-cloud/pubsub';
const pubsub = PubSub();
Expand Down Expand Up @@ -59,7 +59,7 @@ export const integrationTests: any = functions
.ref()
.push().key;
console.log('testId is: ', testId);
fs.writeFile('/tmp/' + testId + '.txt', 'test', ()=> {});
fs.writeFile('/tmp/' + testId + '.txt', 'test', () => {});
return Promise.all([
// A database write to trigger the Firebase Realtime Database tests.
admin
Expand Down Expand Up @@ -93,7 +93,7 @@ export const integrationTests: any = functions
admin.credential
.applicationDefault()
.getAccessToken()
.then((accessToken) => {
.then(accessToken => {
const options = {
hostname: 'firebaseremoteconfig.googleapis.com',
path: `/v1/projects/${firebaseConfig.projectId}/remoteConfig`,
Expand All @@ -110,7 +110,10 @@ export const integrationTests: any = functions
request.end();
}),
// A storage upload to trigger the Storage tests
admin.storage().bucket().upload('/tmp/' + testId + '.txt'),
admin
.storage()
.bucket()
.upload('/tmp/' + testId + '.txt'),
// Invoke a callable HTTPS trigger.
callHttpsTrigger('callableTests', { foo: 'bar', testId }),
])
Expand Down
3 changes: 2 additions & 1 deletion integration_test/functions/src/storage-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const storageTests: any = functions
.runWith({
timeoutSeconds: 540,
})
.storage.bucket().object()
.storage.bucket()
.object()
.onFinalize((s, c) => {
const testId = s.name.split('.')[0];
return new TestSuite<ObjectMetadata>('storage object finalize')
Expand Down
6 changes: 1 addition & 5 deletions spec/function-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ describe('FunctionBuilder', () => {
.auth.user()
.onCreate(user => user);

expect(fn.__trigger.regions).to.deep.equal([
'us-east1',
'us-central1',
]);
expect(fn.__trigger.regions).to.deep.equal(['us-east1', 'us-central1']);
});

it('should allow runtime options to be set', () => {
Expand Down Expand Up @@ -158,5 +155,4 @@ describe('FunctionBuilder', () => {
} as any);
}).to.throw(Error);
});

});
6 changes: 3 additions & 3 deletions spec/providers/database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,17 @@ describe('Database Functions', () => {
return database.resourceToInstanceAndPath(
'projects/_/instances/a.bad.name/refs/bar'
);
}).to.throw(Error)
}).to.throw(Error);
expect(() => {
return database.resourceToInstanceAndPath(
'projects/_/instances/a_different_bad_name/refs/bar'
);
}).to.throw(Error)
}).to.throw(Error);
expect(() => {
return database.resourceToInstanceAndPath(
'projects/_/instances/BAD!!!!/refs/bar'
);
}).to.throw(Error)
}).to.throw(Error);
});
});

Expand Down
35 changes: 19 additions & 16 deletions src/function-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ import * as https from './providers/https';
import * as pubsub from './providers/pubsub';
import * as remoteConfig from './providers/remoteConfig';
import * as storage from './providers/storage';
import { CloudFunction, EventContext, Runnable, TriggerAnnotated } from './cloud-functions';
import {
CloudFunction,
EventContext,
Runnable,
TriggerAnnotated,
} from './cloud-functions';

/**
* Configure the regions that the function is deployed to.
Expand All @@ -41,15 +46,15 @@ import { CloudFunction, EventContext, Runnable, TriggerAnnotated } from './cloud
*/
export function region(...regions: string[]) {
if (!regions.length) {
throw new Error(
"You must specify at least one region"
);
throw new Error('You must specify at least one region');
}
if (
_.difference(
regions,
['us-central1', 'us-east1', 'europe-west1', 'asia-northeast1']
).length
_.difference(regions, [
'us-central1',
'us-east1',
'europe-west1',
'asia-northeast1',
]).length
) {
throw new Error(
"The only valid regions are 'us-central1', 'us-east1', 'europe-west1', and 'asia-northeast1'"
Expand Down Expand Up @@ -80,11 +85,10 @@ export function runWith(runtimeOptions: {
);
}
if (
runtimeOptions.timeoutSeconds > 540 || runtimeOptions.timeoutSeconds < 0
runtimeOptions.timeoutSeconds > 540 ||
runtimeOptions.timeoutSeconds < 0
) {
throw new Error(
"TimeoutSeconds must be between 0 and 540"
);
throw new Error('TimeoutSeconds must be between 0 and 540');
}
return new FunctionBuilder(runtimeOptions);
}
Expand Down Expand Up @@ -131,11 +135,10 @@ export class FunctionBuilder {
);
}
if (
runtimeOptions.timeoutSeconds > 540 || runtimeOptions.timeoutSeconds < 0
runtimeOptions.timeoutSeconds > 540 ||
runtimeOptions.timeoutSeconds < 0
) {
throw new Error(
"TimeoutSeconds must be between 0 and 540"
);
throw new Error('TimeoutSeconds must be between 0 and 540');
}
this.options = _.assign(this.options, runtimeOptions);
return this;
Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ if (!process.env.FIREBASE_CONFIG) {
'Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail'
);
process.env.FIREBASE_CONFIG = JSON.stringify({
databaseURL: `${process.env.DATABASE_URL}` || `https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
storageBucket: `${process.env.STORAGE_BUCKET_URL}` || `${process.env.GCLOUD_PROJECT}.appspot.com`,
databaseURL:
`${process.env.DATABASE_URL}` ||
`https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
storageBucket:
`${process.env.STORAGE_BUCKET_URL}` ||
`${process.env.GCLOUD_PROJECT}.appspot.com`,
projectId: process.env.GCLOUD_PROJECT,
});
} else {
Expand Down