testcontainers / testcontainers/testcontainers-java
`databasename` part of `jdbc:tc` URIs іs ignored when optional host:port pair is omitted
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Java
- Sterne
- 8.7k
- Forks
- 1.9k
- Ø Merge
- 2 T. 17 Std.
- Gemergte PRs (30 T.)
- 9
Beschreibung
Note that this issue is related to behavior mentioned in #1846.
When one uses "host-less URI" as specified on the JDBC support page, e.g.: jdbc:tc:mysql:5.7.12:///mydatabase, DB name is also ignored and a default test name is used instead.
This code fragment from org.testcontainers.jdbc.ConnectionUrl#parseUrl method clearly shows how it is handled:
//In case it matches to the default pattern
Matcher dbInstanceMatcher = Patterns.DB_INSTANCE_MATCHING_PATTERN.matcher(dbHostString);
if (dbInstanceMatcher.matches()) {
databaseHost = Optional.of(dbInstanceMatcher.group(1));
databasePort = Optional.ofNullable(dbInstanceMatcher.group(3)).map(value -> Integer.valueOf(value));
databaseName = Optional.of(dbInstanceMatcher.group(4));
}
then org.testcontainers.containers.JdbcDatabaseContainerProvider#newInstanceFromConnectionUrl defaults DB name to test:
final String databaseName = connectionUrl.getDatabaseName().orElse("test");
In my particular case an init SQL script, which starts with the following instruction, fails with Caused by: java.sql.SQLSyntaxErrorException: Access denied for user 'test'@'%' to 'mydatabase' error:
CREATE DATABASE IF NOT EXISTS `mydatabase`;
Aforementioned documentation page says:
Note that the hostname, port and database name will be ignored; you can leave these as-is or set them to any value.
which apparently is not the case and /// syntax, which includes DB name only, is recommended and multiple examples are provided.
I suggest to improve "host-less" URI handling by honoring DB name and clarify the documentation on this matter. Will make a PR for this if project owners are OK with such resolution.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit org.testcontainers.jdbc.ConnectionUrl#parseUrl und org.testcontainers.containers.JdbcDatabaseContainerProvider#newInstanceFromConnectionUrl und sieh dir anschließend die Dokumentationsseite zur JDBC-Unterstützung an. Bestätige, dass eine URI ohne Host wie jdbc:tc:mysql:5.7.12:///mydatabase den Datenbanknamen beibehält, statt standardmäßig test zu verwenden, und stelle die Dokumentation entsprechend klar.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java, mysql
- Bereich
- databases
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 48/100