Skip to content

Commit 7c7e3f8

Browse files
authored
test: enable proto column tests on emulator (#2056)
1 parent f08d5af commit 7c7e3f8

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcConnectTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
import com.google.cloud.spanner.jdbc.CloudSpannerJdbcConnection;
2828
import com.google.cloud.spanner.jdbc.JdbcDataSource;
2929
import com.google.cloud.spanner.testing.EmulatorSpannerHelper;
30-
import java.io.FileInputStream;
3130
import java.io.IOException;
31+
import java.nio.file.Files;
32+
import java.nio.file.Paths;
3233
import java.sql.Connection;
3334
import java.sql.DriverManager;
3435
import java.sql.ResultSet;
@@ -229,7 +230,7 @@ public void testConnectWithDataSourceWithConflictingValues() throws SQLException
229230
public void testConnectWithOAuthToken() throws Exception {
230231
GoogleCredentials credentials;
231232
if (hasValidKeyFile()) {
232-
credentials = GoogleCredentials.fromStream(new FileInputStream(getKeyFile()));
233+
credentials = GoogleCredentials.fromStream(Files.newInputStream(Paths.get(getKeyFile())));
233234
} else {
234235
try {
235236
credentials = GoogleCredentials.getApplicationDefault();

src/test/java/com/google/cloud/spanner/jdbc/it/ITProtoColumnsTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.cloud.spanner.jdbc.it;
1818

19+
import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.SPANNER_EMULATOR_HOST;
20+
import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
1921
import static org.junit.Assert.assertArrayEquals;
2022
import static org.junit.Assert.assertEquals;
2123
import static org.junit.Assert.assertFalse;
@@ -34,7 +36,6 @@
3436
import com.google.cloud.spanner.jdbc.ProtoMessageType;
3537
import com.google.cloud.spanner.jdbc.it.SingerProto.Genre;
3638
import com.google.cloud.spanner.jdbc.it.SingerProto.SingerInfo;
37-
import com.google.cloud.spanner.testing.EmulatorSpannerHelper;
3839
import com.google.cloud.spanner.testing.RemoteSpannerHelper;
3940
import java.io.InputStream;
4041
import java.sql.Connection;
@@ -68,8 +69,6 @@ public static boolean isUsingGraalVm() {
6869

6970
@BeforeClass
7071
public static void setup() throws Exception {
71-
assumeFalse(
72-
"Proto columns is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator());
7372
assumeFalse("Skipping tests on GraalVM", isUsingGraalVm());
7473
RemoteSpannerHelper testHelper = env.getTestHelper();
7574
final String projectId = testHelper.getInstanceId().getProject();
@@ -87,7 +86,12 @@ public static void setup() throws Exception {
8786
.setDialect(Dialect.GOOGLE_STANDARD_SQL)
8887
.setProtoDescriptors(in)
8988
.build();
90-
final String host = SpannerTestHost.getHost();
89+
final String host;
90+
if (isUsingEmulator()) {
91+
host = System.getenv(SPANNER_EMULATOR_HOST);
92+
} else {
93+
host = SpannerTestHost.getHost();
94+
}
9195

9296
database =
9397
databaseAdminClient
@@ -109,6 +113,9 @@ public static void setup() throws Exception {
109113

110114
in.close();
111115
url = "jdbc:cloudspanner://" + host + "/" + database.getId();
116+
if (isUsingEmulator()) {
117+
url += "?autoConfigEmulator=true";
118+
}
112119
}
113120

114121
@AfterClass
@@ -121,8 +128,6 @@ public static void teardown() {
121128

122129
@Test
123130
public void testNonNullElements() throws Exception {
124-
assumeFalse(
125-
"Proto columns is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator());
126131
assumeFalse("Skipping tests on GraalVM", isUsingGraalVm());
127132
SingerInfo singerInfo =
128133
SingerInfo.newBuilder()
@@ -166,8 +171,6 @@ public void testNonNullElements() throws Exception {
166171

167172
@Test
168173
public void testNullElements() throws Exception {
169-
assumeFalse(
170-
"Proto columns is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator());
171174
assumeFalse("Skipping tests on GraalVM", isUsingGraalVm());
172175
try (Connection connection = DriverManager.getConnection(url);
173176
PreparedStatement ps =
@@ -201,8 +204,6 @@ public void testNullElements() throws Exception {
201204

202205
@Test
203206
public void testUntypedNullElements() throws Exception {
204-
assumeFalse(
205-
"Proto columns is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator());
206207
assumeFalse("Skipping tests on GraalVM", isUsingGraalVm());
207208
try (Connection connection = DriverManager.getConnection(url);
208209
PreparedStatement ps =
@@ -231,8 +232,6 @@ public void testUntypedNullElements() throws Exception {
231232

232233
@Test
233234
public void testInterCompatibility() throws Exception {
234-
assumeFalse(
235-
"Proto columns is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator());
236235
assumeFalse("Skipping tests on GraalVM", isUsingGraalVm());
237236
SingerInfo singerInfo =
238237
SingerInfo.newBuilder()

0 commit comments

Comments
 (0)