11package com .github .takezoe .slick .blocking
22
3- import com .dimafeng .testcontainers .Container
4- import com .dimafeng .testcontainers .ForAllTestContainer
5- import com .dimafeng .testcontainers .JdbcDatabaseContainer
6- import com .dimafeng .testcontainers .MySQLContainer
3+ import org .scalatest .BeforeAndAfterAll
74import org .scalatest .funsuite .AnyFunSuite
5+ import org .testcontainers .containers .JdbcDatabaseContainer
6+ import org .testcontainers .mysql .MySQLContainer
87import org .testcontainers .utility .DockerImageName
9- import slick .jdbc .JdbcBackend
108import slick .jdbc .meta .MTable
119import scala .concurrent .Await
1210import scala .concurrent .ExecutionContext
@@ -24,21 +22,31 @@ class SlickBlockingAPISpecMySQL56 extends SlickBlockingAPISpecMySQL("5.6")
2422
2523abstract class SlickBlockingAPISpecMySQL (mysqlVersion : String )
2624 extends SlickBlockingAPISpecTestContainer (
27- MySQLContainer (mysqlImageVersion = DockerImageName .parse(" mysql:" + mysqlVersion)),
25+ new MySQLContainer (DockerImageName .parse(" mysql:" + mysqlVersion)),
2826 BlockingMySQLDriver
2927 )
3028
3129abstract class SlickBlockingAPISpecTestContainer (
32- override val container : JdbcDatabaseContainer & Container ,
30+ container : JdbcDatabaseContainer [ ? ] ,
3331 profile : BlockingJdbcProfile
3432) extends SlickBlockingAPISpec (profile)
35- with ForAllTestContainer {
33+ with BeforeAndAfterAll {
3634
37- override lazy val db = Tables .profile.blockingApi.Database .forURL(
38- url = container.jdbcUrl,
39- user = container.username,
40- password = container.password,
41- driver = container.driverClassName
35+ override def beforeAll (): Unit = {
36+ super .beforeAll()
37+ container.start()
38+ }
39+
40+ override def afterAll (): Unit = {
41+ super .afterAll()
42+ container.stop()
43+ }
44+
45+ lazy val db = Tables .profile.blockingApi.Database .forURL(
46+ url = container.getJdbcUrl,
47+ user = container.getUsername,
48+ password = container.getPassword,
49+ driver = container.getDriverClassName
4250 )
4351
4452}
0 commit comments