Skip to content

Commit bb89505

Browse files
authored
Add TARGET_BACKEND environment variable. #no-changelog (#11182)
* Add TARGET_BACKEND environment variable. * Add TARGET_BACKEND environment variable.
1 parent 8e49c48 commit bb89505

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#import <FirebaseFirestore/FIRSnapshotMetadata.h>
2727
#import <FirebaseFirestore/FIRTransaction.h>
2828

29+
#include <exception>
2930
#include <memory>
3031
#include <string>
3132
#include <utility>
@@ -187,7 +188,30 @@ + (void)setUpDefaults {
187188
// Check for a MobileHarness configuration, running against nightly or prod, which have live
188189
// SSL certs.
189190
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+
191215
if (project && host) {
192216
defaultProjectId = project;
193217
defaultSettings.host = host;
@@ -210,6 +234,10 @@ + (void)setUpDefaults {
210234
}
211235

212236
// Otherwise fall back on assuming the emulator or localhost.
237+
[self setUpEmulatorDefault];
238+
}
239+
240+
+ (void)setUpEmulatorDefault {
213241
defaultProjectId = @"test-db";
214242

215243
defaultSettings.host = @"localhost:8080";

0 commit comments

Comments
 (0)