https://kotlinlang.org logo
#kotest-contributors
Title
# kotest-contributors
s

sam

10/20/2021, 2:17 PM
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

Emil Kantis

10/20/2021, 9:33 PM
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
27 Views