@@ -2,24 +2,18 @@ package io.github.gitbucket.ci
2
2
3
3
import java .sql .DriverManager
4
4
5
+ import com .dimafeng .testcontainers .{MySQLContainer , PostgreSQLContainer }
5
6
import io .github .gitbucket .solidbase .Solidbase
6
7
import io .github .gitbucket .solidbase .model .Module
7
8
import liquibase .database .core .{H2Database , MySQLDatabase , PostgresDatabase }
9
+ import org .junit .runner .Description
8
10
import org .scalatest .{FunSuite , Tag }
9
-
10
11
import scala .collection .JavaConverters ._
11
- import com .wix .mysql .EmbeddedMysql ._
12
- import com .wix .mysql .config .Charset
13
- import com .wix .mysql .config .MysqldConfig ._
14
- import com .wix .mysql .distribution .Version ._
15
- import ru .yandex .qatools .embed .postgresql .PostgresStarter
16
- import ru .yandex .qatools .embed .postgresql .config .AbstractPostgresConfig .{Credentials , Net , Storage , Timeout }
17
- import ru .yandex .qatools .embed .postgresql .config .PostgresConfig
18
- import ru .yandex .qatools .embed .postgresql .distribution .Version .Main .PRODUCTION
19
12
20
13
object ExternalDBTest extends Tag (" ExternalDBTest" )
21
14
22
15
class MigrationSpec extends FunSuite {
16
+
23
17
val plugin = Class .forName(" Plugin" ).newInstance().asInstanceOf [gitbucket.core.plugin.Plugin ]
24
18
25
19
test(" Migration H2" ) {
@@ -31,53 +25,47 @@ class MigrationSpec extends FunSuite {
31
25
)
32
26
}
33
27
34
- test(" Migration MySQL" , ExternalDBTest ) {
35
- val config = aMysqldConfig(v5_7_latest)
36
- .withPort(3306 )
37
- .withUser(" sa" , " sa" )
38
- .withCharset(Charset .UTF8 )
39
- .withServerVariable(" log_syslog" , 0 )
40
- .withServerVariable(" bind-address" , " 127.0.0.1" )
41
- .build()
42
-
43
- val mysqld = anEmbeddedMysql(config)
44
- .addSchema(" gitbucket" )
45
- .start()
28
+ implicit private val suiteDescription = Description .createSuiteDescription(getClass)
46
29
47
- try {
48
- new Solidbase ().migrate(
49
- DriverManager .getConnection(" jdbc:mysql://localhost:3306/gitbucket?useSSL=false" , " sa" , " sa" ),
50
- Thread .currentThread().getContextClassLoader(),
51
- new MySQLDatabase (),
52
- new Module (plugin.pluginId, plugin.versions.asJava)
53
- )
54
- } finally {
55
- mysqld.stop()
30
+ Seq (" 8.0" , " 5.7" ).foreach { tag =>
31
+ test(s " Migration MySQL $tag" , ExternalDBTest ) {
32
+ val container = new MySQLContainer () {
33
+ override val container = new org.testcontainers.containers.MySQLContainer (s " mysql: $tag" ) {
34
+ override def getDriverClassName = " org.mariadb.jdbc.Driver"
35
+ }
36
+ // TODO https://github.com/testcontainers/testcontainers-java/issues/736
37
+ container.withCommand(" mysqld --default-authentication-plugin=mysql_native_password" )
38
+ }
39
+ container.starting()
40
+ try {
41
+ new Solidbase ().migrate(
42
+ DriverManager .getConnection(s " ${container.jdbcUrl}?useSSL=false " , container.username, container.password),
43
+ Thread .currentThread().getContextClassLoader(),
44
+ new MySQLDatabase (),
45
+ new Module (plugin.pluginId, plugin.versions.asJava)
46
+ )
47
+ } finally {
48
+ container.finished()
49
+ }
56
50
}
57
51
}
58
52
59
- test(" Migration PostgreSQL" , ExternalDBTest ) {
60
- val runtime = PostgresStarter .getDefaultInstance()
61
- val config = new PostgresConfig (
62
- PRODUCTION ,
63
- new Net (" localhost" , 5432 ),
64
- new Storage (" gitbucket" ),
65
- new Timeout (),
66
- new Credentials (" sa" , " sa" )
67
- )
68
-
69
- val exec = runtime.prepare(config)
70
- val process = exec.start()
53
+ Seq (" 11" , " 10" ).foreach { tag =>
54
+ test(s " Migration PostgreSQL $tag" , ExternalDBTest ) {
55
+ val container = PostgreSQLContainer (s " postgres: $tag" )
71
56
72
- try {
73
- new Solidbase ().migrate(
74
- DriverManager .getConnection(" jdbc:postgresql://localhost:5432/gitbucket" , " sa" , " sa" ),
75
- Thread .currentThread().getContextClassLoader(),
76
- new PostgresDatabase (),
77
- new Module (plugin.pluginId, plugin.versions.asJava)
78
- )
79
- } finally {
80
- process.stop()
57
+ container.starting()
58
+ try {
59
+ new Solidbase ().migrate(
60
+ DriverManager .getConnection(container.jdbcUrl, container.username, container.password),
61
+ Thread .currentThread().getContextClassLoader(),
62
+ new PostgresDatabase (),
63
+ new Module (plugin.pluginId, plugin.versions.asJava)
64
+ )
65
+ } finally {
66
+ container.finished()
67
+ }
81
68
}
82
69
}
70
+
83
71
}
0 commit comments