From 3ebd88f369b01d41842c2546e2aa101c8d6c5e17 Mon Sep 17 00:00:00 2001 From: Willem Jan Glerum Date: Mon, 24 Feb 2025 18:08:43 +0100 Subject: [PATCH] Fix SmokeTest - Actually report failure when loading posts (we get a 4xx error when we tried to read from a branch that doesn't exist) - Use loggers instead of println - Set correct github branch for testing - Cleanup SmokeTest --- app/modules/ApplicationStart.scala | 34 +++++++++++++++--------------- conf/application.conf | 2 +- test/integration/SmokeTest.scala | 11 ++++------ 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/app/modules/ApplicationStart.scala b/app/modules/ApplicationStart.scala index 3d2f9fc..6f23427 100644 --- a/app/modules/ApplicationStart.scala +++ b/app/modules/ApplicationStart.scala @@ -22,7 +22,7 @@ class ApplicationStart @Inject()( ws: WSClient, configuration: Configuration, cache: SyncCacheApi - ) { + ) extends Logging { private val accessToken = configuration.get[String]("accessToken") private val organization = configuration.get[String]("githubOrganisation") @@ -33,19 +33,21 @@ class ApplicationStart @Inject()( { // Parse all and put into cache - println("loading posts…") + logger.info("loading posts…") val fPosts = getPosts() - fPosts.map { posts => - cache.set("posts", posts) - println("posts loaded!") - // Construct our author cache - getPostByAuthor(posts).foreach { case (author, posts) => - cache.set("author-" + author, posts) - } + fPosts.map { + case Left(error) => logger.error(error) + case Right(posts) => + cache.set("posts", posts) + logger.info("posts loaded!") + // Construct our author cache + getPostByAuthor(posts).foreach { case (author, posts) => + cache.set("author-" + author, posts) + } - getPostByTag(posts).map { case (tag, posts) => - cache.set("tag-" + tag.trim, posts) - } + getPostByTag(posts).map { case (tag, posts) => + cache.set("tag-" + tag.trim, posts) + } } Await.result(fPosts, 5 minutes) } @@ -88,10 +90,8 @@ class ApplicationStart @Inject()( case Nil => map } - private def getPosts(page: Int = 1): Future[Seq[Post]] = getContents.flatMap { - case Left(e) => - println(e.getMessage) - Future.successful(Seq.empty) + private def getPosts(page: Int = 1): Future[Either[String, Seq[Post]]] = getContents.flatMap { + case Left(e) => Future.successful(Left(e.getMessage)) // Those are our blog post case Right(r) => // Build our posts @@ -142,7 +142,7 @@ class ApplicationStart @Inject()( posts } Future.sequence(posts).map { p => - p.flatten + Right(p.flatten) } } } diff --git a/conf/application.conf b/conf/application.conf index 69cdb04..4e037a2 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -6,7 +6,7 @@ githubOrganisation = lunatech-labs githubOrganisation = ${?github_organisation} githubRepository = lunatech-blog githubRepository = ${?github_repository} -githubBranch = master +githubBranch = main githubBranch = ${?github_branch} blogBackground = "https://lunatech.cdn.prismic.io/lunatech/c01fd6de48c3cdb8bda7247b0b94b84b14f3a488_kevin-horvat-1354011-unsplash.jpg" blogBackground = ${?blog_background} diff --git a/test/integration/SmokeTest.scala b/test/integration/SmokeTest.scala index 5612319..28ea781 100644 --- a/test/integration/SmokeTest.scala +++ b/test/integration/SmokeTest.scala @@ -1,21 +1,18 @@ +package integration 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 +import play.api.libs.ws.WSClient +import play.api.test.Helpers._ class SmokeTest extends PlaySpec with GuiceOneServerPerSuite { override def fakeApplication(): Application = { GuiceApplicationBuilder() .configure( - "accessToken" -> sys.env.get("GITHUB_TOKEN").getOrElse("dummy") + "accessToken" -> sys.env.getOrElse("GITHUB_TOKEN", "dummy") ) .build() }