|
1 | 1 | package unit |
2 | 2 |
|
3 | | -import scalikejdbc._, async._ |
4 | | - |
5 | | -trait DBSettings { |
6 | | - DBSettings.initialize() |
7 | | -} |
8 | | - |
9 | | -object DBSettings { |
10 | | - |
11 | | - private var isInitialized = false |
12 | | - |
13 | | - def initialize(): Unit = this.synchronized { |
14 | | - if (isInitialized) return |
| 3 | +import scalikejdbc._ |
| 4 | +import async._ |
| 5 | +import com.dimafeng.testcontainers.{ ForAllTestContainer, MultipleContainers, MySQLContainer, PostgreSQLContainer } |
| 6 | +import org.scalatest.Suite |
| 7 | + |
| 8 | +trait DBSettings extends ForAllTestContainer { self: Suite => |
| 9 | + // TODO update mysql version |
| 10 | + protected[this] final val mysql = MySQLContainer(mysqlImageVersion = "mysql:5.6.44") |
| 11 | + protected[this] final val postgres = PostgreSQLContainer("postgres:11.4") |
| 12 | + override val container = MultipleContainers(mysql, postgres) |
| 13 | + |
| 14 | + override def afterStart(): Unit = { |
15 | 15 | GlobalSettings.loggingSQLErrors = false |
16 | 16 |
|
17 | 17 | // default: PostgreSQL |
18 | | - ConnectionPool.singleton("jdbc:postgresql://localhost:5432/scalikejdbc", "sa", "sa") |
19 | | - AsyncConnectionPool.singleton("jdbc:postgresql://localhost:5432/scalikejdbc", "sa", "sa") |
| 18 | + ConnectionPool.singleton(url = postgres.jdbcUrl, user = postgres.username, password = postgres.password) |
| 19 | + AsyncConnectionPool.singleton(url = postgres.jdbcUrl, user = postgres.username, password = postgres.password) |
20 | 20 |
|
21 | 21 | SampleDBInitializer.initPostgreSQL() |
22 | 22 | PgListDBInitializer.initPostgreSQL() |
23 | 23 |
|
24 | 24 | // MySQL |
25 | | - ConnectionPool.add('mysql, "jdbc:mysql://localhost:3306/scalikejdbc", "sa", "sa") |
26 | | - AsyncConnectionPool.add('mysql, "jdbc:mysql://localhost:3306/scalikejdbc", "sa", "sa") |
| 25 | + ConnectionPool.add(Symbol("mysql"), url = mysql.jdbcUrl, user = mysql.username, password = mysql.password) |
| 26 | + AsyncConnectionPool.add(Symbol("mysql"), url = mysql.jdbcUrl, user = mysql.username, password = mysql.password) |
27 | 27 |
|
28 | 28 | SampleDBInitializer.initMySQL() |
29 | 29 | PgListDBInitializer.initMySQL() |
30 | 30 | PersonDBInitializer.initMySQL() |
31 | 31 | AccountDBInitializer.initMySQL() |
32 | | - |
33 | | - isInitialized = true |
34 | 32 | } |
35 | 33 |
|
36 | 34 | } |
0 commit comments