Skip to content

Commit c8fa458

Browse files
authored
fix: sets the project for the integration tests (googleapis#386)
The emulator uses the project set in order to list the instance configurations. If the none is set, it gets that information through the gcloud project set, which might mismatch the project being used to create the databases in the integration tests. This PR hardcodes the project so it matches the instance for the integration tests. Note it can still be overridden, instructions were added in the `CONTRIBUTING.md` file.
1 parent 5e89ebb commit c8fa458

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

CONTRIBUTING.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ integration tests.
4848

4949
```bash
5050
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account.json
51-
mvn -Penable-integration-tests clean verify
51+
mvn \
52+
-Penable-integration-tests \
53+
-Dspanner.testenv.instance=projects/<your-project>/instances/<your-instance> \
54+
-Dspanner.gce.config.project_id=<your-project> \
55+
clean verify
5256
```
5357

5458
## Code Samples

google-cloud-spanner/pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<systemPropertyVariables>
7070
<spanner.testenv.config.class>com.google.cloud.spanner.GceTestEnvConfig</spanner.testenv.config.class>
7171
<spanner.testenv.instance>projects/gcloud-devel/instances/spanner-testing</spanner.testenv.instance>
72+
<spanner.gce.config.project_id>gcloud-devel</spanner.gce.config.project_id>
7273
</systemPropertyVariables>
7374
<forkedProcessTimeoutInSeconds>3000</forkedProcessTimeoutInSeconds>
7475
</configuration>
@@ -363,4 +364,4 @@
363364
</build>
364365
</profile>
365366
</profiles>
366-
</project>
367+
</project>

google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntegrationTestEnv.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.cloud.spanner;
1818

19-
import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
2019
import static com.google.common.base.Preconditions.checkState;
2120

2221
import com.google.api.gax.longrunning.OperationFuture;
@@ -80,7 +79,7 @@ protected void before() throws Throwable {
8079
SpannerOptions options = config.spannerOptions();
8180
String instanceProperty = System.getProperty(TEST_INSTANCE_PROPERTY, "");
8281
InstanceId instanceId;
83-
if (!instanceProperty.isEmpty() && !isUsingEmulator()) {
82+
if (!instanceProperty.isEmpty()) {
8483
instanceId = InstanceId.of(instanceProperty);
8584
isOwnedInstance = false;
8685
logger.log(Level.INFO, "Using existing test instance: {0}", instanceId);

0 commit comments

Comments
 (0)