Skip to content

Commit f45266e

Browse files
authored
Adds integration tests for storage triggers, updates README to describe 2 project integration test option (firebase#386)
* Adds integration tests for storage triggers * Documents multiproject option
1 parent fe3d410 commit f45266e

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

integration_test/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
How to Use
22
---------
33

4-
***ATTENTION***: Running this test will wipe the contents of the Firebase project you run it against. Make sure you use a disposable Firebase project!
4+
***ATTENTION***: Running this test will wipe the contents of the Firebase project(s) you run it against. Make sure you use disposable Firebase project(s)!
55

66
Run the integration test as follows:
77

88
```bash
9-
./run_tests.sh <project_id>
9+
./run_tests.sh <project_id> [<project_id2>]
1010
```
11+
If just one project_id is provided, the both the node6 and node8 tests will be run on that project, in series. If two project_ids are provided, the node6 tests will be run on the first project and the node8 tests will be run on the second one, in parallel.
1112

1213
The tests run fully automatically, and will print the result on standard out. The integration test for HTTPS is that it properly kicks off other integration tests and returns a result. From there the other integration test suites will write their results back to the database, where you can check the detailed results if you'd like.

integration_test/functions/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as functions from 'firebase-functions';
22
import * as https from 'https';
33
import * as admin from 'firebase-admin';
44
import { Request, Response } from 'express';
5+
import * as fs from 'fs'
56

67
import * as PubSub from '@google-cloud/pubsub';
78
const pubsub = PubSub();
@@ -12,6 +13,7 @@ export * from './auth-tests';
1213
export * from './firestore-tests';
1314
export * from './https-tests';
1415
export * from './remoteConfig-tests';
16+
export * from './storage-tests';
1517
const numTests = Object.keys(exports).length; // Assumption: every exported function is its own test.
1618

1719
import 'firebase-functions'; // temporary shim until process.env.FIREBASE_CONFIG available natively in GCF(BUG 63586213)
@@ -57,7 +59,7 @@ export const integrationTests: any = functions
5759
.ref()
5860
.push().key;
5961
console.log('testId is: ', testId);
60-
62+
fs.writeFile('/tmp/' + testId + '.txt', 'test', ()=> {});
6163
return Promise.all([
6264
// A database write to trigger the Firebase Realtime Database tests.
6365
admin
@@ -107,6 +109,8 @@ export const integrationTests: any = functions
107109
request.write(JSON.stringify({ version: { description: testId } }));
108110
request.end();
109111
}),
112+
// A storage upload to trigger the Storage tests
113+
admin.storage().bucket().upload('/tmp/' + testId + '.txt'),
110114
// Invoke a callable HTTPS trigger.
111115
callHttpsTrigger('callableTests', { foo: 'bar', testId }),
112116
])
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as functions from 'firebase-functions';
2+
import { TestSuite, expectEq, expectDeepEq } from './testing';
3+
import ObjectMetadata = functions.storage.ObjectMetadata;
4+
const testIdFieldName = 'documentId';
5+
6+
export const storageTests: any = functions
7+
.runWith({
8+
timeoutSeconds: 540,
9+
})
10+
.storage.bucket().object()
11+
.onFinalize((s, c) => {
12+
const testId = s.name.split('.')[0];
13+
return new TestSuite<ObjectMetadata>('storage object finalize')
14+
15+
.it('should not have event.app', (data, context) => !(context as any).app)
16+
17+
.it('should have the right eventType', (snap, context) =>
18+
expectEq(context.eventType, 'google.storage.object.finalize')
19+
)
20+
21+
.it('should have eventId', (snap, context) => context.eventId)
22+
23+
.it('should have timestamp', (snap, context) => context.timestamp)
24+
25+
.run(testId, s, c);
26+
});

integration_test/run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
set -e
55

66
function usage {
7-
echo "Usage: $0 <project_id_node_6> <project_id_node_8>"
7+
echo "Usage: $0 <project_id_node_6> [<project_id_node_8>]"
88
exit 1
99
}
1010

0 commit comments

Comments
 (0)