-
Notifications
You must be signed in to change notification settings - Fork 2
/
IntegrationTestPackaging.scala
85 lines (71 loc) · 2.76 KB
/
IntegrationTestPackaging.scala
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package xyz.driver.sbt
import java.nio.file._
import com.typesafe.sbt.packager.Keys._
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.Docker
import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport._
import sbt.Keys._
import sbt._
import scala.collection.JavaConverters._
object IntegrationTestPackaging extends AutoPlugin {
override def requires = ServicePlugin
override def trigger = allRequirements
object autoImport {
lazy val IntegrationTest = config("it") extend (Test) // make test classes available
}
import autoImport._
private def list(base: Path): Seq[(Path, String)] = base match {
case _ if Files.isDirectory(base) =>
Files.walk(base).iterator().asScala.toSeq.map { file =>
file -> base.relativize(file).toString
}
case file => Seq(file -> file.getFileName.toString)
}
private def configurationSettings =
inConfig(IntegrationTest)(Defaults.configSettings) ++
inConfig(IntegrationTest)(Defaults.testSettings) ++ Seq(
ivyConfigurations := overrideConfigs(IntegrationTest)(ivyConfigurations.value)
)
override def projectSettings =
configurationSettings ++
Seq(
mappings in Universal ++= {
val cp: Seq[(File, String)] = (dependencyClasspath in IntegrationTest).value
.map(_.data.toPath)
.flatMap(list)
.map {
case (file, location) =>
file.toFile -> ("lib-it/" + location)
}
val tests: Seq[(File, String)] = list((packageBin in IntegrationTest).value.toPath)
.map {
case (file, location) =>
file.toFile -> ("lib-it/" + location)
}
val script = {
def libs(mappings: Seq[(File, String)]): String =
mappings
.map {
case (_, location) =>
s"$$bin_dir/../$location"
}
.mkString(":")
s"""|#!/bin/bash
|bin_dir="$$(dirname "$$(readlink -f "$$0")")"
|exec java \\
| -cp "${libs(tests ++ cp)}" \\
| org.scalatest.tools.Runner \\
| -o \\
| -R "${libs(tests)}"
|""".stripMargin
}
val scriptFile = (resourceManaged in IntegrationTest).value / "runit"
IO.write(scriptFile, script)
scriptFile.setExecutable(true)
cp ++ tests ++ Seq(scriptFile -> s"bin/${normalizedName.value}-it")
},
ServicePlugin.autoImport.customCommands := List(
"mkdir -p test",
s"ln -s ${(defaultLinuxInstallLocation in Docker).value}/bin/${normalizedName.value}-it /test/run_integration_test.sh"
)
)
}