-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix problem of starting up mysql 5.7.33 version when user is root (#3953
) Co-authored-by: Richard North <rich.north@gmail.com> Co-authored-by: Ivan Stanislavciuc <istanislavciuc@ebay.com>
- Loading branch information
1 parent
9183f8f
commit f3ffed6
Showing
2 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
modules/mysql/src/test/java/org/testcontainers/containers/MySQLRootAccountTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.testcontainers.containers; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
@Slf4j | ||
@RunWith(Parameterized.class) | ||
public class MySQLRootAccountTest { | ||
|
||
@Parameterized.Parameters(name = "{0}") | ||
public static String[] params() { | ||
return new String[]{ | ||
"mysql:8", | ||
"mysql:5" | ||
}; | ||
} | ||
|
||
@Parameterized.Parameter() | ||
public String image; | ||
|
||
@Test | ||
public void testRootAccountUsageWithDefaultPassword() throws SQLException { | ||
testWithDB(new MySQLContainer<>(image).withUsername("root")); | ||
} | ||
|
||
@Test | ||
public void testRootAccountUsageWithEmptyPassword() throws SQLException { | ||
testWithDB(new MySQLContainer<>(image).withUsername("root").withPassword("")); | ||
} | ||
|
||
@Test | ||
public void testRootAccountUsageWithCustomPassword() throws SQLException { | ||
testWithDB(new MySQLContainer<>(image).withUsername("root").withPassword("not-default")); | ||
} | ||
|
||
private void testWithDB(MySQLContainer<?> db) throws SQLException { | ||
try { | ||
db.withLogConsumer(new Slf4jLogConsumer(log)).start(); | ||
Connection connection = DriverManager.getConnection(db.getJdbcUrl(), db.getUsername(), db.getPassword()); | ||
connection.createStatement().execute("SELECT 1"); | ||
connection.createStatement().execute("set sql_log_bin=0"); // requires root | ||
} finally { | ||
db.close(); | ||
} | ||
} | ||
} |