From cf000a9843da5d0b9eb396bff69c89dc57cb7110 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Sun, 10 Nov 2024 11:40:07 +0100 Subject: [PATCH] Move tests to e2e modules --- build.sbt | 9 +- .../{app => e2e}/src/test/scala/Clients.scala | 0 .../test/scala/ElasticSearchContainer.scala | 0 .../src/test/scala/IntegrationSuite.scala | 141 +++++++++--------- modules/elastic/src/main/scala/study.scala | 7 +- 5 files changed, 74 insertions(+), 83 deletions(-) rename modules/{app => e2e}/src/test/scala/Clients.scala (100%) rename modules/{app => e2e}/src/test/scala/ElasticSearchContainer.scala (100%) rename modules/{app => e2e}/src/test/scala/IntegrationSuite.scala (60%) diff --git a/build.sbt b/build.sbt index 2a20c015..ea6604e3 100644 --- a/build.sbt +++ b/build.sbt @@ -147,9 +147,7 @@ lazy val app = project logback, otel4sMetricts, otel4sSdk, - otel4sPrometheusExporter, - weaver, - testContainers + otel4sPrometheusExporter ), Compile / run / fork := true ) @@ -161,9 +159,9 @@ val e2e = project .settings( publish := {}, publish / skip := true, - libraryDependencies ++= Seq(weaver) + libraryDependencies ++= Seq(testContainers, weaver) ) - .dependsOn(client, app) + .dependsOn(client, app, ingestor) lazy val root = project .in(file(".")) @@ -172,4 +170,3 @@ lazy val root = project addCommandAlias("prepare", "scalafixAll; scalafmtAll") addCommandAlias("check", "; scalafixAll --check ; scalafmtCheckAll") - diff --git a/modules/app/src/test/scala/Clients.scala b/modules/e2e/src/test/scala/Clients.scala similarity index 100% rename from modules/app/src/test/scala/Clients.scala rename to modules/e2e/src/test/scala/Clients.scala diff --git a/modules/app/src/test/scala/ElasticSearchContainer.scala b/modules/e2e/src/test/scala/ElasticSearchContainer.scala similarity index 100% rename from modules/app/src/test/scala/ElasticSearchContainer.scala rename to modules/e2e/src/test/scala/ElasticSearchContainer.scala diff --git a/modules/app/src/test/scala/IntegrationSuite.scala b/modules/e2e/src/test/scala/IntegrationSuite.scala similarity index 60% rename from modules/app/src/test/scala/IntegrationSuite.scala rename to modules/e2e/src/test/scala/IntegrationSuite.scala index 6e01d347..5957f328 100644 --- a/modules/app/src/test/scala/IntegrationSuite.scala +++ b/modules/e2e/src/test/scala/IntegrationSuite.scala @@ -5,6 +5,7 @@ package test import cats.effect.{ IO, Resource } import cats.syntax.all.* import com.comcast.ip4s.* +import lila.search.ingestor.given import lila.search.spec.* import org.http4s.Uri import org.typelevel.log4cats.noop.{ NoOpFactory, NoOpLogger } @@ -51,76 +52,70 @@ object IntegrationSuite extends IOSuite: _.healthCheck() .map(expect.same(_, HealthCheckOutput(ElasticStatus.green))) - test("forum"): _ => + test("forum"): res => Clients .search(uri) .use: service => for - _ <- service.mapping(Index.Forum) - _ <- service - .store( - "forum_id", - Source.forum( - ForumSource( - body = "a forum post", - topic = "chess", - topicId = "chess", - troll = false, - date = Instant.now().toEpochMilli(), - author = "nt9".some - ) - ) + _ <- res.esClient.putMapping(Index.Forum) + _ <- res.esClient.store( + Index.Forum, + Id("forum_id"), + ingestor.ForumSource( + body = "a forum post", + topic = "chess", + topicId = "chess", + troll = false, + date = Instant.now().toEpochMilli(), + author = "nt9".some ) - _ <- service.refresh(Index.Forum) + ) + _ <- res.esClient.refreshIndex(Index.Forum) x <- service.search(Query.forum("chess", false), from, size) y <- service.search(Query.forum("nt9", false), from, size) yield expect(x.hitIds.size == 1 && x == y) - test("team"): _ => + test("team"): res => Clients .search(uri) .use: service => for - _ <- service.mapping(Index.Team) - _ <- service - .store( - "team_id", - Source.team( - TeamSource( - name = "team name", - description = "team description", - 100 - ) - ) + _ <- res.esClient.putMapping(Index.Team) + _ <- res.esClient.store( + Index.Team, + Id("team_id"), + ingestor.TeamSource( + name = "team name", + description = "team description", + 100 ) - _ <- service.refresh(Index.Team) + ) + _ <- res.esClient.refreshIndex(Index.Team) x <- service.search(Query.team("team name"), from, size) y <- service.search(Query.team("team description"), from, size) yield expect(x.hitIds.size == 1 && x == y) - test("study"): _ => + test("study"): res => Clients .search(uri) .use: service => for - _ <- service.mapping(Index.Study) - _ <- service - .store( - "study_id", - Source.study( - StudySource( - name = "study name", - owner = "study owner", - members = List("member1", "member2"), - chapterNames = "names", - chapterTexts = "texts", - likes = 100, - public = true, - topics = List("topic1", "topic2") - ) - ) + _ <- res.esClient.putMapping(Index.Study) + _ <- res.esClient.store( + Index.Study, + Id("study_id"), + ingestor.StudySource( + name = "study name", + owner = "study owner", + members = List("member1", "member2"), + chapterNames = "names", + chapterTexts = "texts", + likes = 100, + public = true, + topics = List("topic1", "topic2") ) - _ <- service.refresh(Index.Study) + ) + _ <- res.esClient.refreshIndex(Index.Study) a <- service.search(Query.study("name"), from, size) b <- service.search(Query.study("study description"), from, size) c <- service.search(Query.study("topic1"), from, size) @@ -136,38 +131,36 @@ object IntegrationSuite extends IOSuite: duration = defaultIntRange, sorting = Sorting("field", "asc") ) - test("game"): _ => + test("game"): res => Clients .search(uri) .use: service => for - _ <- service.mapping(Index.Game) - _ <- service - .store( - "game_id", - Source.game( - GameSource( - status = 1, - turns = 100, - rated = true, - perf = 1, - winnerColor = 1, - date = SearchDateTime.fromInstant(Timestamp(1999, 10, 20, 12, 20, 20).toInstant), - analysed = false, - uids = List("uid1", "uid2").some, - winner = "uid1".some, - loser = "uid2".some, - averageRating = 150.some, - ai = none, - duration = 100.some, - clockInit = 100.some, - clockInc = 200.some, - whiteUser = "white".some, - blackUser = "black".some - ) - ) + _ <- res.esClient.putMapping(Index.Game) + _ <- res.esClient.store( + Index.Game, + Id("game_id"), + ingestor.GameSource( + status = 1, + turns = 100, + rated = true, + perf = 1, + winnerColor = 1, + date = SearchDateTime.fromInstant(Timestamp(1999, 10, 20, 12, 20, 20).toInstant), + analysed = false, + uids = List("uid1", "uid2").some, + winner = "uid1".some, + loser = "uid2".some, + averageRating = 150.some, + ai = none, + duration = 100.some, + clockInit = 100.some, + clockInc = 200.some, + whiteUser = "white".some, + blackUser = "black".some ) - _ <- service.refresh(Index.Game) + ) + _ <- res.esClient.refreshIndex(Index.Game) a <- service.search(defaultGame.copy(perf = List(1)), from, size) b <- service.search(defaultGame.copy(loser = "uid2".some), from, size) c <- service.search(defaultGame, from, size) diff --git a/modules/elastic/src/main/scala/study.scala b/modules/elastic/src/main/scala/study.scala index 2f7b5049..585c7a8c 100644 --- a/modules/elastic/src/main/scala/study.scala +++ b/modules/elastic/src/main/scala/study.scala @@ -25,9 +25,10 @@ case class Study(text: String, userId: Option[String]): val matcher: Query = if parsed.terms.isEmpty then matchAllQuery() else - multiMatchQuery( - parsed.terms.mkString(" ") - ).fields(Study.searchableFields*).analyzer("english").matchType("most_fields") + multiMatchQuery(parsed.terms.mkString(" ")) + .fields(Study.searchableFields*) + .analyzer("english") + .matchType("most_fields") boolQuery() .must: matcher :: List(