@@ -12,21 +12,21 @@ export * from './database-tests';
12
12
export * from './auth-tests' ;
13
13
export * from './firestore-tests' ;
14
14
export * from './https-tests' ;
15
- export * from './remoteConfig-tests' ;
16
- // export * from './storage-tests';
15
+ // export * from './remoteConfig-tests';
16
+ export * from './storage-tests' ;
17
17
const numTests = Object . keys ( exports ) . length ; // Assumption: every exported function is its own test.
18
18
19
19
import 'firebase-functions' ; // temporary shim until process.env.FIREBASE_CONFIG available natively in GCF(BUG 63586213)
20
20
const firebaseConfig = JSON . parse ( process . env . FIREBASE_CONFIG ) ;
21
21
admin . initializeApp ( ) ;
22
22
23
23
// 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 ) {
25
25
return new Promise ( ( resolve , reject ) => {
26
26
const request = https . request (
27
27
{
28
28
method : 'POST' ,
29
- host : 'us-central1-' + firebaseConfig . projectId + '.cloudfunctions.net' ,
29
+ host : 'us-central1-' + firebaseConfig . projectId + '.' + baseUrl ,
30
30
path : '/' + name ,
31
31
headers : {
32
32
'Content-Type' : 'application/json' ,
@@ -51,8 +51,10 @@ export const integrationTests: any = functions
51
51
timeoutSeconds : 540 ,
52
52
} )
53
53
. 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 ( '.' ) ;
54
57
let pubsub : any = require ( '@google-cloud/pubsub' ) ( ) ;
55
-
56
58
const testId = admin
57
59
. database ( )
58
60
. ref ( )
@@ -88,33 +90,33 @@ export const integrationTests: any = functions
88
90
. collection ( 'tests' )
89
91
. doc ( testId )
90
92
. set ( { test : testId } ) ,
93
+ callHttpsTrigger ( 'callableTests' , { foo : 'bar' , testId } , baseUrl ) ,
91
94
// 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
+ // }),
111
114
// A storage upload to trigger the Storage tests
112
115
admin
113
116
. storage ( )
114
117
. bucket ( )
115
118
. upload ( '/tmp/' + testId + '.txt' ) ,
116
119
// Invoke a callable HTTPS trigger.
117
- callHttpsTrigger ( 'callableTests' , { foo : 'bar' , testId } ) ,
118
120
] )
119
121
. then ( ( ) => {
120
122
// On test completion, check that all tests pass and reply "PASS", or provide further details.
0 commit comments