testcontainers / testcontainers/testcontainers-java
`databasename` part of `jdbc:tc` URIs іs ignored when optional host:port pair is omitted
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 8.7k
- フォーク
- 1.9k
- 平均マージ
- 2日 17時間
- マージ済み PR(30日)
- 9
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
org.testcontainers.jdbc.ConnectionUrl#parseUrl と org.testcontainers.containers.JdbcDatabaseContainerProvider#newInstanceFromConnectionUrl から始め、続いて JDBC サポートのドキュメントページを確認してください。jdbc:tc:mysql:5.7.12:///mydatabase のようなホストなしの URI が、デフォルトで test を使用するのではなくデータベース名を保持することを確認し、それに応じてドキュメントを明確にしてください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java, mysql
- 領域
- databases
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 48/100