summaryrefslogtreecommitdiff
path: root/crashboxd/src/test/scala/io/crashbox/ci/BuildStageSpec.scala
blob: ec5ec56582a3a3ad2012e9728118057cd3d675f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 }
import java.io.{ ByteArrayOutputStream, File }
import java.nio.file.Files
import org.scalatest._
import scala.concurrent.Await
import scala.concurrent.duration._

class BuildStageSpec extends FlatSpec with Matchers with BeforeAndAfterAll {

  implicit val system = ActorSystem("crashboxd-buildstage")
  implicit val materializer = ActorMaterializer()
  val executor = new DockerExecutor


  override def beforeAll(): Unit = {
    DockerUtil.ensureImage(executor.dockerClient)
  }

  override def afterAll(): Unit = {
    assert(executor.clean(), "Spawned containers were not removed")
    system.terminate()
  }


  "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")
      }
    }
  }
}