Skip to content

Commit 9d99981

Browse files
authored
Clean up integration test checks for target backend. (#4563)
* Clean up integration test checks for target backend. * Fix log output.
1 parent e35c14d commit 9d99981

File tree

2 files changed

+27
-38
lines changed

2 files changed

+27
-38
lines changed

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/testutil/IntegrationTestUtil.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,25 @@ public static FirestoreProvider provider() {
128128
return provider;
129129
}
130130

131+
private static String getFirestoreHost() {
132+
switch (backend) {
133+
case EMULATOR:
134+
return String.format("%s:%d", EMULATOR_HOST, EMULATOR_PORT);
135+
case QA:
136+
return "staging-firestore.sandbox.googleapis.com";
137+
case NIGHTLY:
138+
return "test-firestore.sandbox.googleapis.com";
139+
case PROD:
140+
default:
141+
return "firestore.googleapis.com";
142+
}
143+
}
144+
145+
private static boolean getSslEnabled() {
146+
// ssl is enabled in all environments except for the emulator.
147+
return !isRunningAgainstEmulator();
148+
}
149+
131150
public static TargetBackend getTargetBackend() {
132151
if (backendForLocalTesting != null) {
133152
return backendForLocalTesting;
@@ -147,35 +166,19 @@ public static TargetBackend getTargetBackend() {
147166
}
148167

149168
public static DatabaseInfo testEnvDatabaseInfo() {
150-
if (backend.equals(TargetBackend.EMULATOR)) {
151-
return new DatabaseInfo(
152-
DatabaseId.forProject(provider.projectId()),
153-
"test-persistenceKey",
154-
String.format("%s:%d", EMULATOR_HOST, EMULATOR_PORT),
155-
/*sslEnabled=*/ false);
156-
} else {
157-
return new DatabaseInfo(
158-
DatabaseId.forProject(provider.projectId()),
159-
"test-persistenceKey",
160-
provider.firestoreHost(backend),
161-
/*sslEnabled=*/ true);
162-
}
169+
return new DatabaseInfo(
170+
DatabaseId.forProject(provider.projectId()),
171+
"test-persistenceKey",
172+
getFirestoreHost(),
173+
getSslEnabled());
163174
}
164175

165176
public static FirebaseFirestoreSettings newTestSettings() {
166-
Logger.debug("IntegrationTestUtil", "target backend is: %s", BuildConfig.TARGET_BACKEND);
167-
177+
Logger.debug("IntegrationTestUtil", "target backend is: %s", backend.name());
168178
FirebaseFirestoreSettings.Builder settings = new FirebaseFirestoreSettings.Builder();
169-
170-
if (backend.equals(TargetBackend.EMULATOR)) {
171-
settings.setHost(String.format("%s:%d", EMULATOR_HOST, EMULATOR_PORT));
172-
settings.setSslEnabled(false);
173-
} else {
174-
settings.setHost(provider.firestoreHost(backend));
175-
}
176-
179+
settings.setHost(getFirestoreHost());
180+
settings.setSslEnabled(getSslEnabled());
177181
settings.setPersistenceEnabled(true);
178-
179182
return settings.build();
180183
}
181184

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/testutil/prod_provider/FirestoreProvider.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import android.content.Context;
1818
import androidx.test.core.app.ApplicationProvider;
1919
import com.google.firebase.firestore.R;
20-
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
2120

2221
/**
2322
* Provides locations of production Firestore and Firebase Rules.
@@ -36,19 +35,6 @@ public FirestoreProvider(Context context) {
3635
this.context = context;
3736
}
3837

39-
public String firestoreHost(IntegrationTestUtil.TargetBackend backend) {
40-
switch (backend) {
41-
case QA:
42-
return "staging-firestore.sandbox.googleapis.com";
43-
case NIGHTLY:
44-
return "test-firestore.sandbox.googleapis.com";
45-
case EMULATOR:
46-
case PROD:
47-
default:
48-
return "firestore.googleapis.com";
49-
}
50-
}
51-
5238
public String projectId() {
5339
return context.getString(R.string.project_id);
5440
}

0 commit comments

Comments
 (0)