|
16 | 16 |
|
17 | 17 | package com.google.cloud.spanner.jdbc;
|
18 | 18 |
|
| 19 | +import static com.google.cloud.spanner.jdbc.JdbcDriver.EXTERNAL_HOST_URL_PATTERN; |
19 | 20 | import static com.google.common.truth.Truth.assertThat;
|
20 | 21 | import static org.junit.Assert.assertEquals;
|
| 22 | +import static org.junit.Assert.assertFalse; |
21 | 23 | import static org.junit.Assert.assertNotNull;
|
22 | 24 | import static org.junit.Assert.assertTrue;
|
23 | 25 | import static org.junit.Assert.fail;
|
|
47 | 49 | import java.util.Collection;
|
48 | 50 | import java.util.Objects;
|
49 | 51 | import java.util.Properties;
|
| 52 | +import java.util.regex.Matcher; |
50 | 53 | import org.junit.AfterClass;
|
51 | 54 | import org.junit.BeforeClass;
|
52 | 55 | import org.junit.Test;
|
@@ -211,4 +214,32 @@ public void testLenient() throws SQLException {
|
211 | 214 | assertThat(jdbc.getCode()).isEqualTo(Code.INVALID_ARGUMENT);
|
212 | 215 | }
|
213 | 216 | }
|
| 217 | + |
| 218 | + @Test |
| 219 | + public void testJdbcExternalHostFormat() { |
| 220 | + Matcher matcherWithoutInstance = |
| 221 | + EXTERNAL_HOST_URL_PATTERN.matcher("jdbc:cloudspanner://localhost:15000/databases/test-db"); |
| 222 | + assertTrue(matcherWithoutInstance.matches()); |
| 223 | + assertEquals("test-db", matcherWithoutInstance.group("DATABASEGROUP")); |
| 224 | + Matcher matcherWithProperty = |
| 225 | + EXTERNAL_HOST_URL_PATTERN.matcher( |
| 226 | + "jdbc:cloudspanner://localhost:15000/instances/default/databases/singers-db?usePlainText=true"); |
| 227 | + assertTrue(matcherWithProperty.matches()); |
| 228 | + assertEquals("default", matcherWithProperty.group("INSTANCEGROUP")); |
| 229 | + assertEquals("singers-db", matcherWithProperty.group("DATABASEGROUP")); |
| 230 | + Matcher matcherWithoutPort = |
| 231 | + EXTERNAL_HOST_URL_PATTERN.matcher( |
| 232 | + "jdbc:cloudspanner://localhost/instances/default/databases/test-db"); |
| 233 | + assertTrue(matcherWithoutPort.matches()); |
| 234 | + assertEquals("default", matcherWithoutPort.group("INSTANCEGROUP")); |
| 235 | + assertEquals("test-db", matcherWithoutPort.group("DATABASEGROUP")); |
| 236 | + Matcher matcherWithProject = |
| 237 | + EXTERNAL_HOST_URL_PATTERN.matcher( |
| 238 | + "jdbc:cloudspanner://localhost:15000/projects/default/instances/default/databases/singers-db"); |
| 239 | + assertFalse(matcherWithProject.matches()); |
| 240 | + Matcher matcherWithoutHost = |
| 241 | + EXTERNAL_HOST_URL_PATTERN.matcher( |
| 242 | + "jdbc:cloudspanner:/instances/default/databases/singers-db"); |
| 243 | + assertFalse(matcherWithoutHost.matches()); |
| 244 | + } |
214 | 245 | }
|
0 commit comments