codacy.test.checker.PostgresReadyChecker.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of codacy-test-bench_2.13 Show documentation
Show all versions of codacy-test-bench_2.13 Show documentation
A library to send events on rabbit-mq
The newest version!
package codacy.test.checker
import java.sql.DriverManager
import scala.concurrent.{ExecutionContext, Future}
import com.whisk.docker.{DockerCommandExecutor, DockerContainerState, DockerReadyChecker}
case class PostgresReadyChecker(
user: String,
password: String,
port: Option[Int],
host: Option[String],
andThen: () => Future[Boolean] = () => Future.successful(true)
) extends DockerReadyChecker {
override def apply(container: DockerContainerState)(implicit docker: DockerCommandExecutor, ec: ExecutionContext) = {
container
.getPorts()(docker, ec)
.map { p =>
Class.forName("org.postgresql.Driver")
val url =
s"jdbc:postgresql://${host.get}:${port.getOrElse(p)}/?loggerLevel=OFF"
val res = Option(DriverManager.getConnection(url, user, password)).map(_.close).isDefined
if (res)
println(s"Postgres started on port: ${port.getOrElse(p)}")
res
}(ec)
.flatMap { res =>
if (res) andThen()
else Future(false)(ec)
}(ec)
}
}