我正在尝试从 docker-it-scala 旋转一个 docker 容器. 目标是能够针对容器中的 redis 运行单元测试,而不是作为托管服务 (AWS ElastiCache) 的产品
我构建了一个服务,紧跟
import com.spotify.docker.client.{DefaultDockerClient, DockerClient}
import com.whisk.docker.impl.spotify.SpotifyDockerFactory
import com.whisk.docker.{DockerContainer, DockerFactory, DockerKit, DockerReadyChecker}
// Look at https://github.com/whisklabs/docker-it-scala
// .. and let yourself be inspired
trait DockerRedisService extends DockerKit {
val redisDefaultPort = 6379
val redisContainer = DockerContainer("redis")
.withPorts(redisDefaultPort -> None)
.withReadyChecker(DockerReadyChecker.LogLineContains("Ready to accept connections"))
abstract override def dockerContainers: List[DockerContainer] =
redisContainer :: super.dockerContainers
}
从那里,我应该能够运行一些单元测试
class ElastiCache extends FlatSpec with Matchers with BeforeAndAfter with ScalaFutures with DockerRedisService {
private val client: DockerClient = DefaultDockerClient.fromEnv().build()
override implicit val dockerFactory: DockerFactory = new SpotifyDockerFactory(client)
implicit val pc = PatienceConfig(Span(40, Seconds), Span(1, Second))
"the redis container" should "be ready with log line checker" in {
isContainerReady(redisContainer).futureValue shouldBe true
redisContainer.getPorts().futureValue.get(6379 ) should not be empty
redisContainer.getIpAddresses().futureValue should not be Seq.empty
}
单元测试只是在没有太多信息的情况下超时。
看看我如何从那个 redis 中 hset 和 hget 一些值会很有用。
最佳答案
您缺少指定 java-docker 后端的执行特征。
您的 ElastiCache 类
应该扩展一个或另一个:
使用docker-testkit-impl-docker-java
with DockerTestKit with DockerKitDockerJava
使用docker-testkit-impl-spotify
with DockerTestKit with DockerKitDockerSpotify
关于scala - 从 docker-it-scala 旋转 redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48510658/