I wrote a simple repository to test Kotlin Exposed with TestContainers. The database that I use is mysql.
Here is my code :
class StudentsRepositoryTest: ShouldSpec({
val container = getMysqlContainer()
val mysqlJdbcUrl = container.jdbcUrl
beforeSpec {
Database.connect(mysqlJdbcUrl, "com.mysql.cj.jdbc.Driver")
transaction {
SchemaUtils.create(Students)
}
}
... // some tests
private fun getMysqlContainer(): MySQLContainer<Nothing> {
return MySQLContainer<Nothing>("mysql:5.7").apply {
withUsername("root")
withPassword("")
withEnv("MYSQL_ROOT_PASSWORD", "%")
withDatabaseName("test")
start()
}
}
The code fails at the beforeSpec
Access denied for user ''@'172.17.0.1' (using password: NO)
Maybe I am missing something, any help would be appreciated
The libraries that I used :
- kotest
- kotest-extension-testcontainers
- testcontainers
- testcontainers-mysql