From b492dcf46718f50ca051017bddd4551faa867339 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Sun, 9 Apr 2017 16:32:19 -0700 Subject: Refactor testing utilities --- .../scala/io/crashbox/ci/DockerExecutorSpec.scala | 34 ++++------------------ 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'crashboxd/src/test/scala/io/crashbox/ci/DockerExecutorSpec.scala') diff --git a/crashboxd/src/test/scala/io/crashbox/ci/DockerExecutorSpec.scala b/crashboxd/src/test/scala/io/crashbox/ci/DockerExecutorSpec.scala index 5ec95cd..bd3159b 100644 --- a/crashboxd/src/test/scala/io/crashbox/ci/DockerExecutorSpec.scala +++ b/crashboxd/src/test/scala/io/crashbox/ci/DockerExecutorSpec.scala @@ -14,36 +14,13 @@ import org.scalatest._ import scala.util.Random -object DockerUtil { - import TestUtil._ - - val defaultImage = "crashbox" - - def ensureImage(client: DockerClient): Unit = { - println("Pulling base docker image for running docker tests") - val baseImage = "debian:jessie-backports" - client.pull(baseImage) - - withTempFile { dir => - println("Adapting base image for tests") - val modifications = s"""|FROM $baseImage - |RUN adduser crashbox - |USER crashbox - |""".stripMargin - Files.write((new File(dir, "Dockerfile")).toPath, modifications.getBytes) - client.build(dir.toPath, defaultImage) - } - } - -} - class DockerExecutorSpec extends FlatSpec with Matchers with BeforeAndAfterAll with BeforeAndAfterEach { - import TestUtil._ + import IOUtil._ val image = "crashbox" @@ -69,9 +46,9 @@ class DockerExecutorSpec assert(exec.clean(), "Spawned containers were not removed") } - def run[A](script: String)(tests: (Int, File, String) => A): A = withTempFile { - dir => - val out = new ByteArrayOutputStream(1024) + def run[A](script: String)(tests: (Int, File, String) => A): A = withTemp { + case (dir, out) => + val awaitable = for (id <- exec.start(image, script, dir, out); status <- exec.result(id)) yield { status @@ -123,9 +100,8 @@ class DockerExecutorSpec } it should "allow cancellations" in { - withTempFile { dir => + withTemp { case (dir, out) => val script = "while true; do sleep 1; echo sleeping; done" - val out = new ByteArrayOutputStream(1024) val id = Await.result(exec.start(image, script, dir, out), timeout) val check = exec.result(id).map { res => -- cgit v1.2.3