Guest User

Untitled

a guest
Nov 14th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import doobie._
  2. import cats.effect._
  3. import cats.effect.IO
  4. import doobie.specs2._
  5. import io.chrisdavenport.testcontainersspecs2._
  6. import org.specs2.mutable.Specification
  7. import com.dimafeng.testcontainers.GenericContainer
  8. import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy
  9. import java.time.Duration
  10. import java.time.temporal.ChronoUnit.SECONDS
  11.  
  12. class IODoobieQueriesSpec extends QueriesSpec[IO] {
  13. // Using this instead of IOAnalysisMatchers to avoid uninitialized field error
  14. override implicit val M: Effect[IO] = IO.ioConcurrentEffect
  15. }
  16.  
  17. trait QueriesSpec[F[_]] extends Specification with Checker[F] with ForAllTestContainer {
  18. sequential
  19.  
  20. // IMPORTANT: MUST BE LAZY VAL
  21. override lazy val container = GenericContainer(
  22. "christopherdavenport/postgres-db-with-role:latest",
  23. List(5432),
  24. Map(
  25. "POSTGRES_DB" -> dbName,
  26. "POSTGRES_USER" -> dbUserName,
  27. "POSTGRES_PASSWORD" -> dbPassword,
  28. "POSTGRES_ROLE" -> dbName
  29. ),
  30. waitStrategy = new LogMessageWaitStrategy()
  31. .withRegEx(".*database system is ready to accept connections.*\\s")
  32. .withTimes(2)
  33. .withStartupTimeout(Duration.of(60, SECONDS))
  34. )
  35.  
  36. lazy val driverName = "org.postgresql.Driver"
  37. lazy val jdbcUrl = s"jdbc:postgresql://${container.container.getContainerIpAddress()}:${container.container.getMappedPort(5432)}/${dbName}"
  38. lazy val dbUserName = "dbUser"
  39. lazy val dbPassword = "password"
  40. lazy val dbName = "dbName"
  41.  
  42. lazy val transactor = Transactor.fromDriverManager[F](
  43. driverName,
  44. jdbcUrl,
  45. dbUserName,
  46. dbPassword
  47. )
  48.  
  49. override def afterStart : Unit =
  50. Migrations.makeMigrations[IO](jdbcUrl, dbUserName, dbPassword).unsafeRunSync() // My Migration Utility
  51.  
  52. check("select 1".query[Int])
  53. }
Add Comment
Please, Sign In to add comment