I don't know if anyone else uses test containers, ...
# kotest-contributors
s
I don't know if anyone else uses test containers, but using the new mountable extensions in kotest 5.0 we can do something like this:
Copy code
class DatabaseContainerTest : FunSpec() {
   init {

      val mysql = MySQLContainer<Nothing>("mysql:8.0.26").apply {
         withInitScript("init.sql")
         startupAttempts = 1
         withUrlParam("connectionTimeZone", "Z")
         withUrlParam("zeroDateTimeBehavior", "convertToNull")
      }

      val ds = install(JdbcTestContainerExtension(mysql)) {
         maximumPoolSize = 8
         minimumIdle = 4
      }

      test("read from database") {
         ds.connection.use {
            val rs = it.createStatement().executeQuery("SELECT * FROM hashtags")
            rs.next()
            rs.getString("tag") shouldBe "startrek"
         }
      }
   }
}
e
nice! 🙂 At work, we currently make our CI-pipeline go through some hoops to setup containers for testing.. this looks way more convenient to use