Skip to content

Commit

Permalink
modified unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sagnghos committed Feb 21, 2025
1 parent 77ebbfa commit 5cb64bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private String appendPropertiesToUrl(String url, Properties info) {

@Override
public boolean acceptsURL(String url) {
return URL_PATTERN.matcher(url).matches();
return URL_PATTERN.matcher(url).matches() || EXTERNAL_HOST_URL_PATTERN.matcher(url).matches();
}

@Override
Expand Down
19 changes: 5 additions & 14 deletions src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.util.Objects;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -230,37 +229,29 @@ public void testAcceptsURL() throws SQLException {

@Test
public void testJdbcExternalHostFormat() {
Matcher matcher =
Pattern.compile("jdbc:\\(\\?:([a-z]+):.*").matcher(EXTERNAL_HOST_URL_PATTERN.pattern());
String prefix = matcher.matches() ? matcher.group(1) : null;
Matcher matcherWithoutInstance =
EXTERNAL_HOST_URL_PATTERN.matcher(
String.format("jdbc:%s://localhost:15000/databases/test-db", prefix));
EXTERNAL_HOST_URL_PATTERN.matcher("jdbc:cloudspanner://localhost:15000/databases/test-db");
assertTrue(matcherWithoutInstance.matches());
assertEquals("test-db", matcherWithoutInstance.group("DATABASEGROUP"));
Matcher matcherWithProperty =
EXTERNAL_HOST_URL_PATTERN.matcher(
String.format(
"jdbc:%s://localhost:15000/instances/default/databases/singers-db?usePlainText=true",
prefix));
"jdbc:cloudspanner://localhost:15000/instances/default/databases/singers-db?usePlainText=true");
assertTrue(matcherWithProperty.matches());
assertEquals("default", matcherWithProperty.group("INSTANCEGROUP"));
assertEquals("singers-db", matcherWithProperty.group("DATABASEGROUP"));
Matcher matcherWithoutPort =
EXTERNAL_HOST_URL_PATTERN.matcher(
String.format("jdbc:%s://localhost/instances/default/databases/test-db", prefix));
"jdbc:cloudspanner://localhost/instances/default/databases/test-db");
assertTrue(matcherWithoutPort.matches());
assertEquals("default", matcherWithoutPort.group("INSTANCEGROUP"));
assertEquals("test-db", matcherWithoutPort.group("DATABASEGROUP"));
Matcher matcherWithProject =
EXTERNAL_HOST_URL_PATTERN.matcher(
String.format(
"jdbc:%s://localhost:15000/projects/default/instances/default/databases/singers-db",
prefix));
"jdbc:cloudspanner://localhost:15000/projects/default/instances/default/databases/singers-db");
assertFalse(matcherWithProject.matches());
Matcher matcherWithoutHost =
EXTERNAL_HOST_URL_PATTERN.matcher(
String.format("jdbc:%s:/instances/default/databases/singers-db", prefix));
"jdbc:cloudspanner:/instances/default/databases/singers-db");
assertFalse(matcherWithoutHost.matches());
}
}

0 comments on commit 5cb64bc

Please sign in to comment.