From b3903eb747c3a26cca52b9581dd878c56487beed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Richez?= Date: Wed, 4 Oct 2023 12:37:56 +0200 Subject: [PATCH 1/3] remove play json from the dependencies It should not be necessary since it's pulled by the play framework --- build.sbt | 1 - 1 file changed, 1 deletion(-) diff --git a/build.sbt b/build.sbt index 3d24001..c1c2894 100644 --- a/build.sbt +++ b/build.sbt @@ -12,7 +12,6 @@ libraryDependencies ++= Seq( "org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % Test, "org.asciidoctor" % "asciidoctorj" % "2.5.10", "com.47deg" %% "github4s" % "0.21.0", - "com.typesafe.play" %% "play-json" % "2.10.1", ) Global / onChangedBuildSource := ReloadOnSourceChanges From 8a99753db50a7418bbe9a268775ef18ed2b5c496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Richez?= Date: Wed, 4 Oct 2023 12:38:20 +0200 Subject: [PATCH 2/3] Add a smoke test for the application --- .github/workflows/scala.yml | 4 ++++ .github/workflows/smoke_test.sh | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 .github/workflows/smoke_test.sh diff --git a/.github/workflows/scala.yml b/.github/workflows/scala.yml index e3e9b28..89a9c48 100644 --- a/.github/workflows/scala.yml +++ b/.github/workflows/scala.yml @@ -20,3 +20,7 @@ jobs: distribution: 'adopt' - name: Run tests run: sbt test + - name: Smoke test + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: .github/workflows/smoke_test.sh diff --git a/.github/workflows/smoke_test.sh b/.github/workflows/smoke_test.sh new file mode 100755 index 0000000..b220b47 --- /dev/null +++ b/.github/workflows/smoke_test.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -euo pipefail + +TRY_COUNT=30 +sbt stage + +cd target/universal/stage + +APPLICATION_SECRET="9w/DBOjdTE?65hO5IzGu_XL5^AiK^>iUZgIF?mYVUbPNjNU[ver>zw[V@zlbb0wu" access_token=$GITHUB_TOKEN bin/lunatech-blog-engine & + +PID=$! +trap "kill $! 2> /dev/null" EXIT + +is_running() { + kill -0 $PID 2> /dev/null +} + +is_responding() { + curl localhost:9000 -s -o /dev/null +} + +for (( count=0; count < $TRY_COUNT; count++ )); do + if ! is_running; then + echo "::error::The application stopped before it could serve a page." + exit 1 + fi + + if is_responding; then + exit 0 + fi + + sleep 3 +done + +echo "::error::Timeout: the application did not serve a page in time." +exit 2 From 98724bc676a77844c07f7430ea56b9e7d7c03793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Richez?= Date: Thu, 5 Oct 2023 10:41:47 +0200 Subject: [PATCH 3/3] add smoke test in scalatest instead of bash script --- .github/workflows/scala.yml | 4 +--- .github/workflows/smoke_test.sh | 36 -------------------------------- test/integration/SmokeTest.scala | 28 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 39 deletions(-) delete mode 100755 .github/workflows/smoke_test.sh create mode 100644 test/integration/SmokeTest.scala diff --git a/.github/workflows/scala.yml b/.github/workflows/scala.yml index 89a9c48..477fcce 100644 --- a/.github/workflows/scala.yml +++ b/.github/workflows/scala.yml @@ -19,8 +19,6 @@ jobs: java-version: '11' distribution: 'adopt' - name: Run tests - run: sbt test - - name: Smoke test env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: .github/workflows/smoke_test.sh + run: sbt test diff --git a/.github/workflows/smoke_test.sh b/.github/workflows/smoke_test.sh deleted file mode 100755 index b220b47..0000000 --- a/.github/workflows/smoke_test.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -TRY_COUNT=30 -sbt stage - -cd target/universal/stage - -APPLICATION_SECRET="9w/DBOjdTE?65hO5IzGu_XL5^AiK^>iUZgIF?mYVUbPNjNU[ver>zw[V@zlbb0wu" access_token=$GITHUB_TOKEN bin/lunatech-blog-engine & - -PID=$! -trap "kill $! 2> /dev/null" EXIT - -is_running() { - kill -0 $PID 2> /dev/null -} - -is_responding() { - curl localhost:9000 -s -o /dev/null -} - -for (( count=0; count < $TRY_COUNT; count++ )); do - if ! is_running; then - echo "::error::The application stopped before it could serve a page." - exit 1 - fi - - if is_responding; then - exit 0 - fi - - sleep 3 -done - -echo "::error::Timeout: the application did not serve a page in time." -exit 2 diff --git a/test/integration/SmokeTest.scala b/test/integration/SmokeTest.scala new file mode 100644 index 0000000..5612319 --- /dev/null +++ b/test/integration/SmokeTest.scala @@ -0,0 +1,28 @@ + +import org.scalatestplus.play.PlaySpec +import org.scalatestplus.play.guice.GuiceOneServerPerSuite +import play.api.libs.ws.WSClient +import org.scalatest._ +import org.scalatestplus.play._ + +import play.api.test._ +import play.api.test.Helpers.{GET => GET_REQUEST, _} +import play.api.Application +import play.api.inject.guice.GuiceApplicationBuilder + +class SmokeTest extends PlaySpec with GuiceOneServerPerSuite { + + override def fakeApplication(): Application = { + GuiceApplicationBuilder() + .configure( + "accessToken" -> sys.env.get("GITHUB_TOKEN").getOrElse("dummy") + ) + .build() + } + + "should return some page" in { + val wsClient = app.injector.instanceOf[WSClient] + val response = await(wsClient.url(s"http://localhost:$port/").withVirtualHost("blog.lunatech.com").get()) + response.status mustBe OK + } +}