whisklabs/docker-it-scala
소개
Scala용 Docker 통합 테스트 키트입니다.
시스템 및 인프라측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originaldocker-it-scala
Set of utility classes to make integration testing with dockerised services in Scala easy.
You can read about reasoning behind it at Finely Distributed.
Setup
docker-it-scala works with Spotify's docker-client to communicate to docker engine through REST API or unix socket.
- Spotify's docker-client (used in Whisk)
libraryDependencies ++= Seq(
"com.whisk" %% "docker-testkit-scalatest" % "0.11.0" % "test"
Configuration
You should be able to provide configuration purely through environment variables.
Examples:
export DOCKER_HOST=tcp://127.0.0.1:2375
export DOCKER_HOST=unix:///var/run/docker.sock
Sample Services
Defining Containers
There are two ways to define a docker container.
Code based definitions and via typesafe-config.
Code based definitions
import com.whisk.docker.testkit.scalatest.DockerTestKitForAll
import org.scalatest.Suite
trait DockerMongodbService extends DockerTestKitForAll {
self: Suite =>
val DefaultMongodbPort = 27017
val mongodbContainer = ContainerSpec("mongo:3.4.8")
.withExposedPorts(DefaultMongodbPort)
.withReadyChecker(DockerReadyChecker.LogLineContains("waiting for connections on port"))
.toContainer
override val managedContainers: ManagedContainers = mongodbContainer.toManagedContainer
}
You can check usage example
Container Paths
- Elasticsearch =>
docker.elasticsearch - Mongodb =>
docker.mongo - Neo4j =>
docker.mysql - Postgres =>
docker.postgres - Clickhouse =>
docker.clickhouse
Fields
image-namerequired (String)container-nameoptional (String)commandoptional (Array of Strings)entrypointoptional (Array of Strings)environmental-variablesoptional (Array of Strings)ready-checkeroptional structurelog-lineoptional (String)http-response-codecodeoptional (Int - defaults to200)portrequired (Int)pathoptional (String - defaults to/)withinoptional (Int)loopedoptional structureattemptsrequired (Int)delayrequired (Int)
port-mapsoptional structure (list of structures)SOME_MAPPING_NAMEinternalrequired (Int)externaloptional (Int)
volume-mapsoptional structure (list of structures)containerrequired (String)hostrequired (String)rwoptional (Boolean - default:false)
memoryoptional (Long)memory-reservationoptional (Long)
Testkit
There are two testkits available -- one for scalatest and one for
specs2.
Both set up the necessary docker containers and check that they are ready BEFORE any test is run, and doesn't close the container until ALL the tests are run.
Using in ScalaTest:
class MyMongoSpec extends FlatSpec with Matchers with DockerMongodbService {
...
}
With Multiple containers:
class MultiContainerTest
extends AnyFunSuite
with DockerElasticsearchService
with DockerMongodbService {
override val managedContainers: ContainerGroup =
ContainerGroup.of(elasticsearchContainer, mongodbContainer)
test("both containers should be ready") {
assert(
elasticsearchContainer.state().isInstanceOf[ContainerState.Ready],
"elasticsearch container is ready"
)
assert(elasticsearchContainer.mappedPortOpt(9200).nonEmpty, "elasticsearch port is exposed")
assert(mongodbContainer.state().isInstanceOf[ContainerState.Ready], "mongodb is ready")
assert(mongodbContainer.mappedPortOpt(27017).nonEmpty, "port 2017 is exposed")
}
}
관련 프로젝트 살펴보기
불러오는 중…