summaryrefslogtreecommitdiff
path: root/crashboxd/src/test/scala/io/crashbox/ci/BuildStageSpec.scala
diff options
context:
space:
mode:
Diffstat (limited to 'crashboxd/src/test/scala/io/crashbox/ci/BuildStageSpec.scala')
-rw-r--r--crashboxd/src/test/scala/io/crashbox/ci/BuildStageSpec.scala74
1 files changed, 34 insertions, 40 deletions
diff --git a/crashboxd/src/test/scala/io/crashbox/ci/BuildStageSpec.scala b/crashboxd/src/test/scala/io/crashbox/ci/BuildStageSpec.scala
index a3a68b6..ec5ec56 100644
--- a/crashboxd/src/test/scala/io/crashbox/ci/BuildStageSpec.scala
+++ b/crashboxd/src/test/scala/io/crashbox/ci/BuildStageSpec.scala
@@ -1,6 +1,7 @@
package io.crashbox.ci
import akka.actor.ActorSystem
+import akka.stream.scaladsl.Keep
import akka.stream.{ ClosedShape, KillSwitch }
import akka.stream.scaladsl.{ GraphDSL, RunnableGraph, Sink, Source }
import akka.stream.{ ActorMaterializer, FanInShape2 }
@@ -10,54 +11,47 @@ import org.scalatest._
import scala.concurrent.Await
import scala.concurrent.duration._
-class BuildStageSpec extends FlatSpec with Matchers with DockerSuite{
+class BuildStageSpec extends FlatSpec with Matchers with BeforeAndAfterAll {
+ implicit val system = ActorSystem("crashboxd-buildstage")
implicit val materializer = ActorMaterializer()
+ val executor = new DockerExecutor
- val exec = new DockerExecutor
- def withTmp[A](action: (File, ByteArrayOutputStream) => A): A = {
- val dir = Files.createTempDirectory("crashbox-build-stage-test").toFile
- val out = new ByteArrayOutputStream(1024)
- try action(dir, out)
- finally dir.delete()
+ override def beforeAll(): Unit = {
+ DockerUtil.ensureImage(executor.dockerClient)
}
- "BuildStage" should "have a test!" in {
- withTmp{ case (dir, out) =>
- val taskDef = TaskDef(DockerEnvironment("crashbox"), "sleep 100; exit 0")
-
- val resultSink = Sink.foreach[Builder.BuildState](x => println(x))
-
- val graph = RunnableGraph.fromGraph(GraphDSL.create(resultSink) {
- implicit b => sink =>
- import GraphDSL.Implicits._
-
- val builder = b.add(new BuildStage(exec, _ => dir, _ => out))
-
- val submissions = b.add(
- Source.repeat(TaskId("123", 2) -> taskDef))
- val cancellations = b.add(
- Source.tick(10.seconds, 10.seconds, TaskId("0", 0)))
-
- val ks = b.add(KillSwitch)
-
- submissions ~> builder.in0
- cancellations ~> builder.in1
-
- builder.out ~> sink
+ override def afterAll(): Unit = {
+ assert(executor.clean(), "Spawned containers were not removed")
+ system.terminate()
+ }
- ClosedShape
- })
- graph.run()
- Thread.sleep(30000)
- println("terminating")
- Await.result(system.terminate(), 60.seconds)
- println("teminated")
- Thread.sleep(5000)
- println("eot")
+ "BuildStage" should "have a test!" in {
+ TestUtil.withTempFile{ dir =>
+ TestUtil.withTempStream{ out =>
+
+ val taskDef = TaskDef(DockerEnvironment("crashbox"), "sleep 10; exit 0")
+ val resultSink = Sink.foreach[Builder.BuildState](x => println(x))
+
+ val stage = new BuildSource(
+ TaskId("build", 0),
+ taskDef,
+ executor,
+ dir,
+ out
+ )
+ val src = Source.fromGraph(stage)
+
+ //val done = src.toMat(resultSink)(Keep.right).run()
+
+ //executor.start("crashbox", "sleep 10000", dir, out)
+ Thread.sleep(1000)
+ assert(executor.clean())
+ //Await.ready(done, 30.seconds)
+ println("eot")
+ }
}
-
}
}