Skip to content

Commit

Permalink
Use root user when interacting with MySQL
Browse files Browse the repository at this point in the history
Without this, we'll see the following permission exceptions for some
of our tests:

```
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'test'@'%' to database 'two'
org.jetbrains.exposed.exceptions.ExposedSQLException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'test'@'%' to database 'two'
SQL: [CREATE SCHEMA IF NOT EXISTS two]
	at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_core(Statement.kt:63)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:129)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:115)
```
  • Loading branch information
KushalP committed Jul 7, 2020
1 parent 4a9c972 commit 621889b
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ enum class TestDB(val connection: () -> String, val driver: String, val user: St
SQLITE({"jdbc:sqlite:file:test?mode=memory&cache=shared"}, "org.sqlite.JDBC"),
MYSQL(
connection = { "${mySQLProcess.jdbcUrl}?createDatabaseIfNotExist=true&characterEncoding=UTF-8&useSSL=false" },
user = mySQLProcess.username,
pass = mySQLProcess.password,
user = "root",
pass = "test",
driver = "com.mysql.jdbc.Driver",
beforeConnection = { mySQLProcess },
afterTestFinished = { mySQLProcess.close() }
Expand Down Expand Up @@ -84,9 +84,12 @@ private val postgresSQLProcess by lazy {
internal class SpecifiedMySQLContainer(val image: String) : MySQLContainer<SpecifiedMySQLContainer>(image)

private val mySQLProcess by lazy {
SpecifiedMySQLContainer(image = "mysql:5").withDatabaseName("testdb").withExposedPorts().apply {
start()
}
SpecifiedMySQLContainer(image = "mysql:5")
.withDatabaseName("testdb")
.withEnv("MYSQL_ROOT_PASSWORD", "test")
.withExposedPorts().apply {
start()
}
}

abstract class DatabaseTestsBase {
Expand Down

0 comments on commit 621889b

Please sign in to comment.