Skip to content

Clean up integration test checks for target backend. #4563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@ public static FirestoreProvider provider() {
return provider;
}

private static String getFirestoreHost() {
switch (backend) {
case EMULATOR:
return String.format("%s:%d", EMULATOR_HOST, EMULATOR_PORT);
case QA:
return "staging-firestore.sandbox.googleapis.com";
case NIGHTLY:
return "test-firestore.sandbox.googleapis.com";
case PROD:
default:
return "firestore.googleapis.com";
}
}

private static boolean getSslEnabled() {
// ssl is enabled in all environments except for the emulator.
return !isRunningAgainstEmulator();
}

public static TargetBackend getTargetBackend() {
if (backendForLocalTesting != null) {
return backendForLocalTesting;
Expand All @@ -147,35 +166,19 @@ public static TargetBackend getTargetBackend() {
}

public static DatabaseInfo testEnvDatabaseInfo() {
if (backend.equals(TargetBackend.EMULATOR)) {
return new DatabaseInfo(
DatabaseId.forProject(provider.projectId()),
"test-persistenceKey",
String.format("%s:%d", EMULATOR_HOST, EMULATOR_PORT),
/*sslEnabled=*/ false);
} else {
return new DatabaseInfo(
DatabaseId.forProject(provider.projectId()),
"test-persistenceKey",
provider.firestoreHost(backend),
/*sslEnabled=*/ true);
}
return new DatabaseInfo(
DatabaseId.forProject(provider.projectId()),
"test-persistenceKey",
getFirestoreHost(),
getSslEnabled());
}

public static FirebaseFirestoreSettings newTestSettings() {
Logger.debug("IntegrationTestUtil", "target backend is: %s", BuildConfig.TARGET_BACKEND);

Logger.debug("IntegrationTestUtil", "target backend is: %s", backend.name());
FirebaseFirestoreSettings.Builder settings = new FirebaseFirestoreSettings.Builder();

if (backend.equals(TargetBackend.EMULATOR)) {
settings.setHost(String.format("%s:%d", EMULATOR_HOST, EMULATOR_PORT));
settings.setSslEnabled(false);
} else {
settings.setHost(provider.firestoreHost(backend));
}

settings.setHost(getFirestoreHost());
settings.setSslEnabled(getSslEnabled());
settings.setPersistenceEnabled(true);

return settings.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import com.google.firebase.firestore.R;
import com.google.firebase.firestore.testutil.IntegrationTestUtil;

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

public String firestoreHost(IntegrationTestUtil.TargetBackend backend) {
switch (backend) {
case QA:
return "staging-firestore.sandbox.googleapis.com";
case NIGHTLY:
return "test-firestore.sandbox.googleapis.com";
case EMULATOR:
case PROD:
default:
return "firestore.googleapis.com";
}
}

public String projectId() {
return context.getString(R.string.project_id);
}
Expand Down