26
26
#import < FirebaseFirestore/FIRSnapshotMetadata.h>
27
27
#import < FirebaseFirestore/FIRTransaction.h>
28
28
29
+ #include < exception>
29
30
#include < memory>
30
31
#include < string>
31
32
#include < utility>
@@ -187,7 +188,30 @@ + (void)setUpDefaults {
187
188
// Check for a MobileHarness configuration, running against nightly or prod, which have live
188
189
// SSL certs.
189
190
NSString *project = [[NSProcessInfo processInfo ] environment ][@" PROJECT_ID" ];
190
- NSString *host = [[NSProcessInfo processInfo ] environment ][@" DATASTORE_HOST" ];
191
+ NSString *targetBackend = [[NSProcessInfo processInfo ] environment ][@" TARGET_BACKEND" ];
192
+ NSString *host;
193
+ if (targetBackend) {
194
+ if ([targetBackend isEqualToString: @" emulator" ]) {
195
+ [self setUpEmulatorDefault ];
196
+ return ;
197
+ } else if ([targetBackend isEqualToString: @" qa" ]) {
198
+ host = @" staging-firestore.sandbox.googleapis.com" ;
199
+ } else if ([targetBackend isEqualToString: @" nightly" ]) {
200
+ host = @" test-firestore.sandbox.googleapis.com" ;
201
+ } else if ([targetBackend isEqualToString: @" prod" ]) {
202
+ host = @" firestore.googleapis.com" ;
203
+ } else {
204
+ @throw [[NSException alloc ]
205
+ initWithName: @" InvalidArgumentError"
206
+ reason: [NSString stringWithFormat:
207
+ @" Unexpected TARGET_BACKEND environment variable \" %@ \" " ,
208
+ targetBackend]
209
+ userInfo: nil ];
210
+ }
211
+ } else {
212
+ host = [[NSProcessInfo processInfo ] environment ][@" DATASTORE_HOST" ];
213
+ }
214
+
191
215
if (project && host) {
192
216
defaultProjectId = project;
193
217
defaultSettings.host = host;
@@ -210,6 +234,10 @@ + (void)setUpDefaults {
210
234
}
211
235
212
236
// Otherwise fall back on assuming the emulator or localhost.
237
+ [self setUpEmulatorDefault ];
238
+ }
239
+
240
+ + (void )setUpEmulatorDefault {
213
241
defaultProjectId = @" test-db" ;
214
242
215
243
defaultSettings.host = @" localhost:8080" ;
0 commit comments