@@ -12,21 +12,21 @@ export * from './database-tests';
1212export * from './auth-tests' ;
1313export * from './firestore-tests' ;
1414export * from './https-tests' ;
15- export * from './remoteConfig-tests' ;
16- // export * from './storage-tests';
15+ // export * from './remoteConfig-tests';
16+ export * from './storage-tests' ;
1717const numTests = Object . keys ( exports ) . length ; // Assumption: every exported function is its own test.
1818
1919import 'firebase-functions' ; // temporary shim until process.env.FIREBASE_CONFIG available natively in GCF(BUG 63586213)
2020const firebaseConfig = JSON . parse ( process . env . FIREBASE_CONFIG ) ;
2121admin . 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