Skip to content

Commit 1183c67

Browse files
authored
Toggling off remote config tests, toggling on storage tests, fixing https tests (#410)
* toggling on storage tests, off remote config tests * minor changes * changing target of https function based on environment * removing unneeded config * adding clarifying comment
1 parent ac94e4e commit 1183c67

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

integration_test/functions/src/index.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ export * from './database-tests';
1212
export * from './auth-tests';
1313
export * from './firestore-tests';
1414
export * from './https-tests';
15-
export * from './remoteConfig-tests';
16-
// export * from './storage-tests';
15+
// export * from './remoteConfig-tests';
16+
export * from './storage-tests';
1717
const numTests = Object.keys(exports).length; // Assumption: every exported function is its own test.
1818

1919
import 'firebase-functions'; // temporary shim until process.env.FIREBASE_CONFIG available natively in GCF(BUG 63586213)
2020
const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);
2121
admin.initializeApp();
2222

2323
// TODO(klimt): Get rid of this once the JS client SDK supports callable triggers.
24-
function callHttpsTrigger(name: string, data: any) {
24+
function callHttpsTrigger(name: string, data: any, baseUrl) {
2525
return new Promise((resolve, reject) => {
2626
const request = https.request(
2727
{
2828
method: 'POST',
29-
host: 'us-central1-' + firebaseConfig.projectId + '.cloudfunctions.net',
29+
host: 'us-central1-' + firebaseConfig.projectId + '.' + baseUrl,
3030
path: '/' + name,
3131
headers: {
3232
'Content-Type': 'application/json',
@@ -51,8 +51,10 @@ export const integrationTests: any = functions
5151
timeoutSeconds: 540,
5252
})
5353
.https.onRequest((req: Request, resp: Response) => {
54+
// We take the base url for our https call (cloudfunctions.net, txckloud.net, etc) from the request
55+
// so that it changes with the environment that the tests are run in
56+
const baseUrl = req.hostname.split('.').slice(1).join('.');
5457
let pubsub: any = require('@google-cloud/pubsub')();
55-
5658
const testId = admin
5759
.database()
5860
.ref()
@@ -88,33 +90,33 @@ export const integrationTests: any = functions
8890
.collection('tests')
8991
.doc(testId)
9092
.set({ test: testId }),
93+
callHttpsTrigger('callableTests', { foo: 'bar', testId }, baseUrl),
9194
// A Remote Config update to trigger the Remote Config tests.
92-
admin.credential
93-
.applicationDefault()
94-
.getAccessToken()
95-
.then(accessToken => {
96-
const options = {
97-
hostname: 'firebaseremoteconfig.googleapis.com',
98-
path: `/v1/projects/${firebaseConfig.projectId}/remoteConfig`,
99-
method: 'PUT',
100-
headers: {
101-
Authorization: 'Bearer ' + accessToken.access_token,
102-
'Content-Type': 'application/json; UTF-8',
103-
'Accept-Encoding': 'gzip',
104-
'If-Match': '*',
105-
},
106-
};
107-
const request = https.request(options, resp => {});
108-
request.write(JSON.stringify({ version: { description: testId } }));
109-
request.end();
110-
}),
95+
// admin.credential
96+
// .applicationDefault()
97+
// .getAccessToken()
98+
// .then(accessToken => {
99+
// const options = {
100+
// hostname: 'firebaseremoteconfig.googleapis.com',
101+
// path: `/v1/projects/${firebaseConfig.projectId}/remoteConfig`,
102+
// method: 'PUT',
103+
// headers: {
104+
// Authorization: 'Bearer ' + accessToken.access_token,
105+
// 'Content-Type': 'application/json; UTF-8',
106+
// 'Accept-Encoding': 'gzip',
107+
// 'If-Match': '*',
108+
// },
109+
// };
110+
// const request = https.request(options, resp => {});
111+
// request.write(JSON.stringify({ version: { description: testId } }));
112+
// request.end();
113+
// }),
111114
// A storage upload to trigger the Storage tests
112115
admin
113116
.storage()
114117
.bucket()
115118
.upload('/tmp/' + testId + '.txt'),
116119
// Invoke a callable HTTPS trigger.
117-
callHttpsTrigger('callableTests', { foo: 'bar', testId }),
118120
])
119121
.then(() => {
120122
// On test completion, check that all tests pass and reply "PASS", or provide further details.

0 commit comments

Comments
 (0)