Skip to content
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

Spanner: Allow specifying a custom credentials file for integration tests #4782

Merged
Merged
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 @@ -18,6 +18,7 @@

import static com.google.common.base.Preconditions.checkState;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.spanner.spi.v1.SpannerInterceptorProvider;
import io.grpc.CallOptions;
import io.grpc.Channel;
Expand All @@ -28,13 +29,16 @@
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.Status;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;

/** Configure TestEnv based on configuration provided. */
public class GceTestEnvConfig implements TestEnvConfig {
public static final String GCE_PROJECT_ID = "spanner.gce.config.project_id";
public static final String GCE_SERVER_URL = "spanner.gce.config.server_url";
public static final String GCE_CREDENTIALS_FILE = "spanner.gce.config.credentials_file";
public static final String GCE_STREAM_BROKEN_PROBABILITY =
"spanner.gce.config.stream_broken_probability";

Expand All @@ -43,6 +47,7 @@ public class GceTestEnvConfig implements TestEnvConfig {
public GceTestEnvConfig() {
String projectId = System.getProperty(GCE_PROJECT_ID, "");
String serverUrl = System.getProperty(GCE_SERVER_URL, "");
String credentialsFile = System.getProperty(GCE_CREDENTIALS_FILE, "");
double errorProbability =
Double.parseDouble(System.getProperty(GCE_STREAM_BROKEN_PROBABILITY, "0.0"));
checkState(errorProbability <= 1.0);
Expand All @@ -53,6 +58,13 @@ public GceTestEnvConfig() {
if (!serverUrl.isEmpty()) {
builder.setHost(serverUrl);
}
if (!credentialsFile.isEmpty()) {
try {
builder.setCredentials(GoogleCredentials.fromStream(new FileInputStream(credentialsFile)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
options =
builder
.setInterceptorProvider(
Expand Down