All Downloads are FREE. Search and download functionalities are using the official Maven repository.

codacy.test.GlobalEnvironment.scala Maven / Gradle / Ivy

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
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy