Skip to content

Commit

Permalink
Fix SmokeTest (#122)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
wjglerum authored Feb 24, 2025
1 parent 310726f commit 2645b1b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
34 changes: 17 additions & 17 deletions app/modules/ApplicationStart.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -142,7 +142,7 @@ class ApplicationStart @Inject()(
posts
}
Future.sequence(posts).map { p =>
p.flatten
Right(p.flatten)
}
}
}
2 changes: 1 addition & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
11 changes: 4 additions & 7 deletions test/integration/SmokeTest.scala
Original file line number Diff line number Diff line change
@@ -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()
}
Expand Down

0 comments on commit 2645b1b

Please sign in to comment.