testcontainers / testcontainers/testcontainers-java
`databasename` part of `jdbc:tc` URIs іs ignored when optional host:port pair is omitted
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 8.7k
- Fork
- 1.9k
- Merge medio
- 2g 17h
- PR unite (30g)
- 9
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da org.testcontainers.jdbc.ConnectionUrl#parseUrl e org.testcontainers.containers.JdbcDatabaseContainerProvider#newInstanceFromConnectionUrl, quindi esamina la pagina della documentazione sul supporto JDBC. Verifica che un URI privo di host come jdbc:tc:mysql:5.7.12:///mydatabase mantenga il nome del database invece di usare test come valore predefinito e chiarisci di conseguenza la documentazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java, mysql
- Ambito
- databases
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 48/100