Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import doobie._
- import cats.effect._
- import cats.effect.IO
- import doobie.specs2._
- import io.chrisdavenport.testcontainersspecs2._
- import org.specs2.mutable.Specification
- import com.dimafeng.testcontainers.GenericContainer
- import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy
- import java.time.Duration
- import java.time.temporal.ChronoUnit.SECONDS
- class IODoobieQueriesSpec extends QueriesSpec[IO] {
- // Using this instead of IOAnalysisMatchers to avoid uninitialized field error
- override implicit val M: Effect[IO] = IO.ioConcurrentEffect
- }
- trait QueriesSpec[F[_]] extends Specification with Checker[F] with ForAllTestContainer {
- sequential
- // IMPORTANT: MUST BE LAZY VAL
- override lazy val container = GenericContainer(
- "christopherdavenport/postgres-db-with-role:latest",
- List(5432),
- Map(
- "POSTGRES_DB" -> dbName,
- "POSTGRES_USER" -> dbUserName,
- "POSTGRES_PASSWORD" -> dbPassword,
- "POSTGRES_ROLE" -> dbName
- ),
- waitStrategy = new LogMessageWaitStrategy()
- .withRegEx(".*database system is ready to accept connections.*\\s")
- .withTimes(2)
- .withStartupTimeout(Duration.of(60, SECONDS))
- )
- lazy val driverName = "org.postgresql.Driver"
- lazy val jdbcUrl = s"jdbc:postgresql://${container.container.getContainerIpAddress()}:${container.container.getMappedPort(5432)}/${dbName}"
- lazy val dbUserName = "dbUser"
- lazy val dbPassword = "password"
- lazy val dbName = "dbName"
- lazy val transactor = Transactor.fromDriverManager[F](
- driverName,
- jdbcUrl,
- dbUserName,
- dbPassword
- )
- override def afterStart : Unit =
- Migrations.makeMigrations[IO](jdbcUrl, dbUserName, dbPassword).unsafeRunSync() // My Migration Utility
- check("select 1".query[Int])
- }
Add Comment
Please, Sign In to add comment