Skip to content

Commit d842e2a

Browse files
committed
add test for project dependency
1 parent b8f9960 commit d842e2a

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

src/sbt-test/docker/test-layer-groups-playframework/app/controllers/HomeController.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package controllers
22

3-
import javax.inject._
4-
import play.api._
3+
import common.Common
54
import play.api.mvc._
65

6+
import javax.inject._
7+
78
/**
89
* This controller creates an `Action` to handle HTTP requests to the
910
* application's home page.
@@ -21,4 +22,6 @@ class HomeController @Inject()(val controllerComponents: ControllerComponents) e
2122
def index() = Action { implicit request: Request[AnyContent] =>
2223
Ok(views.html.index())
2324
}
25+
26+
def helloWorld = Action(Ok(Common.helloWorld))
2427
}

src/sbt-test/docker/test-layer-groups-playframework/build.sbt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
name := "test-layer-groups-playframework"
2-
organization := "com.example"
32

4-
version := "1.0-SNAPSHOT"
3+
ThisBuild / organization := "com.example"
4+
ThisBuild / version := "1.0-SNAPSHOT"
5+
ThisBuild / scalaVersion := "2.13.16"
56

6-
lazy val root = (project in file(".")).enablePlugins(PlayScala)
7+
lazy val root = (project in file(".")).enablePlugins(PlayScala).dependsOn(common)
78

8-
scalaVersion := "2.13.16"
9+
// a local project dependency
10+
lazy val common = project.settings(
11+
name := "test-layer-groups-playframework-common",
12+
13+
// a transitive dependency of the main project
14+
// (use any library as long as it's not already a Play dependency)
15+
libraryDependencies += "org.typelevel" %% "cats-core" % "2.13.0"
16+
)
917

1018
libraryDependencies += guice
1119
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "7.0.1" % Test
@@ -32,6 +40,7 @@ TaskKey[Unit]("checkDockerLayers") := {
3240
layer20.forall(_.file.getPath.startsWith(csrCacheDirectory.value.getPath)),
3341
"layer 20 should only contain external libraries"
3442
)
43+
assert(layer20.exists(_.file.name.contains("cats-core")), "layer 20 should contain the common project's dependencies")
3544

3645
val layer30 = layers(Some(30))
3746
assert(layer30.exists(_.path == "/opt/docker/conf/application.ini"), "layer 30 should contain application.ini")
@@ -44,6 +53,10 @@ TaskKey[Unit]("checkDockerLayers") := {
4453
)
4554
assert(layer40.exists(_.file == PlayKeys.playPackageAssets.value), "layer 40 should contain Play's -assets.jar")
4655
assert(layer40.exists(_.file == packageJavaLauncherJar.value), "layer 40 should contain launcher jar")
56+
assert(
57+
layer40.exists(_.file == (common / Compile / packageBin).value),
58+
"layer 40 should contain the common project jar"
59+
)
4760
assert(
4861
layer40.exists(layer => makeBashScripts.value.map(_._1).contains(layer.file)),
4962
"layer 40 should contain start scripts"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package common
2+
3+
import cats.syntax.show._
4+
5+
object Common {
6+
def helloWorld: String = show"Hello, world!"
7+
}

src/sbt-test/docker/test-layer-groups-playframework/conf/routes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# An example controller showing a sample home page
77
GET / controllers.HomeController.index()
8+
GET /hello-world controllers.HomeController.helloWorld
89

910
# Map static resources from the /public folder to the /assets URL path
1011
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)

0 commit comments

Comments
 (0)