Skip to content

Commit 70b290c

Browse files
committed
first trial for testcontainers
1 parent 1d7daf8 commit 70b290c

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import BuildSettings._
33
import sbtassembly.AssemblyPlugin.autoImport.assemblyMergeStrategy
44
import com.typesafe.sbt.packager.docker._
55

6-
lazy val commonDeps = Seq(logback, scalaTest, scalaCheck, akkaHttpSprayJson, embeddedPg, embeddedPgSupport, apacheCommonsIO, s3Mock,log4jToSlf4j, kubernetesApi)
6+
lazy val commonDeps = Seq(logback, scalaTest, scalaCheck, akkaHttpSprayJson, embeddedPg, apacheCommonsIO, s3Mock,log4jToSlf4j, kubernetesApi)
77

88
lazy val sparkDeps =
99
Seq(

common/src/test/scala/hmda/utils/EmbeddedPostgres.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package hmda.utils
22

33
import org.scalatest.{ BeforeAndAfterAll, BeforeAndAfterEach, Suite }
4-
import ru.yandex.qatools.embed.postgresql.distribution.Version
4+
import org.testcontainers.containers.FixedHostPortGenericContainer
55
import slick.basic.DatabaseConfig
66
import slick.dbio.DBIO
77
import slick.jdbc.JdbcProfile
@@ -16,7 +16,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
1616
* after each test and finally deletes all tables before the suite is complete and tears down the database
1717
*/
1818
trait EmbeddedPostgres extends BeforeAndAfterAll with BeforeAndAfterEach { self: Suite =>
19-
private val embeddedPg = new ru.yandex.qatools.embed.postgresql.EmbeddedPostgres(Version.V11_1)
19+
private val embeddedPg = new FixedHostPortGenericContainer("postgres:12")
2020
val dbHoconpath = "embedded-pg"
2121
val dbConfig = DatabaseConfig.forConfig[JdbcProfile](dbHoconpath)
2222

@@ -48,15 +48,19 @@ trait EmbeddedPostgres extends BeforeAndAfterAll with BeforeAndAfterEach { self:
4848
}
4949

5050
override protected def beforeAll(): Unit = {
51-
embeddedPg.start("localhost", 5432, "postgres", "postgres", "postgres")
51+
embeddedPg.withEnv("POSTGRES_USER", "postgres")
52+
embeddedPg.withEnv("POSTGRES_PASSWORD", "postgres")
53+
embeddedPg.withEnv("POSTGRES_DB", "postgres")
54+
embeddedPg.withFixedExposedPort(5432, 5432)
55+
embeddedPg.start()
5256
executeSQL(removeAllTables)
5357
loadSqlFileFromResources(bootstrapSqlFile)
5458
super.beforeAll()
5559
}
5660

5761
override protected def afterAll(): Unit = {
5862
executeSQL(removeAllTables)
59-
embeddedPg.close()
63+
embeddedPg.stop()
6064
super.afterAll()
6165
}
6266

project/Dependencies.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ object Dependencies {
5454
lazy val alpakkaSlick = "com.lightbend.akka" %% "akka-stream-alpakka-slick" % Version.alpakka
5555
lazy val postgres = "org.postgresql" % "postgresql" % Version.postgres
5656
lazy val h2 = "com.h2database" % "h2" % Version.h2 % Test
57-
lazy val embeddedPg =
58-
"ru.yandex.qatools.embed" % "postgresql-embedded" % Version.embeddedPg % Test exclude ("de.flapdoodle.embed", "de.flapdoodle.embed.process")
59-
lazy val embeddedPgSupport = "de.flapdoodle.embed" % "de.flapdoodle.embed.process" % "2.1.2" % Test
57+
lazy val embeddedPg = "org.testcontainers" % "postgresql" % "1.18.0" % "test"
6058
lazy val s3Mock = "com.adobe.testing" % "s3mock" % "2.1.19" % Test
6159
lazy val apacheCommonsIO = "commons-io" % "commons-io" % "2.6" % Test
6260
lazy val keycloakAdapter = "org.keycloak" % "keycloak-adapter-core" % Version.keycloak

0 commit comments

Comments
 (0)