codacy.test.GlobalEnvironment.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
import codacy.test.docker.PortHelper
import com.spotify.docker.client.{DefaultDockerClient, DockerClient}
import com.whisk.docker.impl.spotify.SpotifyDockerFactory
import com.whisk.docker.{DockerContainer, DockerFactory, DockerKit}
import scala.collection.mutable
import scala.concurrent.duration._
// Global environemtn to be used outside tests (e.g. in build definition)
class GlobalEnvironment extends DockerKit with NetworkHelper with PortHelper {
private val client: DockerClient = DefaultDockerClient.fromEnv().build()
override implicit val dockerFactory: DockerFactory = new SpotifyDockerFactory(client)
override val StartContainersTimeout = 360.seconds
private val ports: mutable.Map[String, Int] = mutable.Map()
private val containers: mutable.ListBuffer[DockerContainer] = mutable.ListBuffer()
/*
* bind a string name to a port that will be binded
*/
def bindPort(name: String): Int = {
val port = genPort()
ports.update(name, port)
port
}
def getPort(name: String): Option[Int] = {
ports.get(name)
}
def registerContainer(container: DockerContainer) =
containers += container
def registerContainers(containers0: DockerContainer*) =
containers ++= containers0
def allContainers() = containers.toList
override def dockerContainers: List[DockerContainer] =
allContainers() ::: super.dockerContainers
}