From ddb2e457545ab6f223ab4d06a6c05ecd81186135 Mon Sep 17 00:00:00 2001 From: Rohan Sircar Date: Sat, 17 Apr 2021 23:35:10 +0530 Subject: [PATCH] temp commit --- build.sbt | 68 ++++++------------- captain-definition | 2 +- project/plugins.sbt | 2 +- .../DatabaseIntegrationTestBase.scala | 1 + .../doge/http4sdemo/LibraryServiceSpec.scala | 0 .../wow/doge/http4sdemo/MonixBioSuite.scala | 35 ++++++++++ .../http4sdemo/LibraryControllerSpec.scala | 3 +- .../wow/doge/http4sdemo/LibrarySpec2.scala | 51 -------------- .../wow/doge/http4sdemo/MonixBioSuite.scala | 7 +- 9 files changed, 62 insertions(+), 107 deletions(-) rename src/{test => it}/scala/wow/doge/http4sdemo/DatabaseIntegrationTestBase.scala (98%) rename src/{test => it}/scala/wow/doge/http4sdemo/LibraryServiceSpec.scala (100%) create mode 100644 src/it/scala/wow/doge/http4sdemo/MonixBioSuite.scala delete mode 100644 src/test/scala/wow/doge/http4sdemo/LibrarySpec2.scala diff --git a/build.sbt b/build.sbt index ca95aa4..3976e6f 100644 --- a/build.sbt +++ b/build.sbt @@ -44,6 +44,7 @@ lazy val flyway = (project in file("modules/flyway")) lazy val root = (project in file(".")) .enablePlugins(CodegenPlugin, DockerPlugin, JavaAppPackaging, AshScriptPlugin) + .configs(IntegrationTest) .settings( organization := "wow.doge", name := "http4s-demo", @@ -58,6 +59,7 @@ lazy val root = (project in file(".")) dockerBaseImage := dockerJavaImage, dockerExposedPorts := Seq(8081), dockerUsername := Some("rohansircar"), + Defaults.itSettings, scalacOptions ++= Seq( "-encoding", "UTF-8", @@ -85,8 +87,8 @@ lazy val root = (project in file(".")) "org.http4s" %% "http4s-circe" % Http4sVersion, "org.http4s" %% "http4s-dsl" % Http4sVersion, "io.circe" %% "circe-generic" % CirceVersion, - "org.scalameta" %% "munit" % MunitVersion % Test, - "org.typelevel" %% "munit-cats-effect-2" % MunitCatsEffectVersion % Test, + "org.scalameta" %% "munit" % MunitVersion % "it,test", + "org.typelevel" %% "munit-cats-effect-2" % MunitCatsEffectVersion % "it,test", "ch.qos.logback" % "logback-classic" % LogbackVersion, "org.scalameta" %% "svm-subs" % "20.2.0", "co.fs2" %% "fs2-reactive-streams" % "2.5.0", @@ -125,57 +127,18 @@ lazy val root = (project in file(".")) "com.rms.miu" %% "slick-cats" % "0.10.4", "com.kubukoz" %% "slick-effect" % "0.3.0", "io.circe" %% "circe-fs2" % "0.13.0", - // "org.scalameta" %% "munit" % "0.7.23" % Test, - "de.lolhens" %% "munit-tagless-final" % "0.0.1" % Test, - "org.scalameta" %% "munit-scalacheck" % "0.7.23" % Test, - "org.scalacheck" %% "scalacheck" % "1.15.3" % Test, - "com.dimafeng" %% "testcontainers-scala-munit" % "0.39.3" % Test, - "com.dimafeng" %% "testcontainers-scala-postgresql" % "0.39.3" % Test + // "org.scalameta" %% "munit" % "0.7.23" % "it,test", + "de.lolhens" %% "munit-tagless-final" % "0.0.1" % "it,test", + "org.scalameta" %% "munit-scalacheck" % "0.7.23" % "it,test", + "org.scalacheck" %% "scalacheck" % "1.15.3" % "it,test", + "com.dimafeng" %% "testcontainers-scala-munit" % "0.39.3" % IntegrationTest, + "com.dimafeng" %% "testcontainers-scala-postgresql" % "0.39.3" % IntegrationTest ), addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3"), addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"), - ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.4.3", - inThisBuild( - List( - scalaVersion := scalaVersion.value, // 2.11.12, or 2.13.3 - semanticdbEnabled := true, // enable SemanticDB - semanticdbVersion := "4.4.2" // use Scalafix compatible version - ) - ), - testFrameworks += new TestFramework("munit.Framework"), - assemblyMergeStrategy in assembly := { - case PathList("javax", "servlet", xs @ _*) => MergeStrategy.first - case PathList(ps @ _*) if ps.last endsWith ".html" => MergeStrategy.first - case "application.conf" => MergeStrategy.concat - case "unwanted.txt" => MergeStrategy.discard - case x if Assembly.isConfigFile(x) => - MergeStrategy.concat - case PathList("META-INF", xs @ _*) => - (xs map { _.toLowerCase }) match { - case ("manifest.mf" :: Nil) | ("index.list" :: Nil) | - ("dependencies" :: Nil) => - MergeStrategy.discard - case ps @ (x :: xs) - if ps.last.endsWith(".sf") || ps.last.endsWith(".dsa") => - MergeStrategy.discard - case "plexus" :: xs => - MergeStrategy.discard - case "services" :: xs => - MergeStrategy.filterDistinctLines - case ("spring.schemas" :: Nil) | ("spring.handlers" :: Nil) => - MergeStrategy.filterDistinctLines - case _ => MergeStrategy.first // Changed deduplicate to first - } - case PathList(_*) => MergeStrategy.first - } + testFrameworks += new TestFramework("munit.Framework") ) .settings( - // libraryDependencies ++= Seq( - // "com.zaxxer" % "HikariCP" % "3.4.2", - // "com.typesafe.slick" %% "slick" % "3.3.2", - // "com.typesafe.slick" %% "slick-hikaricp" % "3.3.2", - // "com.h2database" % "h2" % "1.4.199" - // ), slickCodegenDatabaseUrl := databaseUrl, slickCodegenDatabaseUser := databaseUser, slickCodegenDatabasePassword := databasePassword, @@ -200,3 +163,12 @@ lazy val root = (project in file(".")) sourceGenerators in Compile += slickCodegen.taskValue ) .dependsOn(flyway) + +ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.4.3" +inThisBuild( + List( + scalaVersion := scalaVersion.value, // 2.11.12, or 2.13.3 + semanticdbEnabled := true, // enable SemanticDB + semanticdbVersion := "4.4.2" // use Scalafix compatible version + ) +) diff --git a/captain-definition b/captain-definition index b21671d..502ae4b 100644 --- a/captain-definition +++ b/captain-definition @@ -1,4 +1,4 @@ { "schemaVersion": 2, - "imageName": "rohansircar/http4s-demo:0.0.1" + "imageName": "rohansircar/http4s-demo:latest" } \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index 7cce819..8f9eb49 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,5 @@ // addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.14") addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1") -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10") // https://github.com/tototoshi/sbt-slick-codegen libraryDependencies += "com.h2database" % "h2" % "1.4.196" @@ -14,3 +13,4 @@ addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.23") addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.8.0") addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") diff --git a/src/test/scala/wow/doge/http4sdemo/DatabaseIntegrationTestBase.scala b/src/it/scala/wow/doge/http4sdemo/DatabaseIntegrationTestBase.scala similarity index 98% rename from src/test/scala/wow/doge/http4sdemo/DatabaseIntegrationTestBase.scala rename to src/it/scala/wow/doge/http4sdemo/DatabaseIntegrationTestBase.scala index f2f5ef7..8f5c56f 100644 --- a/src/test/scala/wow/doge/http4sdemo/DatabaseIntegrationTestBase.scala +++ b/src/it/scala/wow/doge/http4sdemo/DatabaseIntegrationTestBase.scala @@ -11,6 +11,7 @@ import monix.execution.Scheduler import org.testcontainers.utility.DockerImageName import slick.jdbc.JdbcBackend import slick.jdbc.PostgresProfile +import wow.doge.http4sdemo.MonixBioSuite trait DatabaseIntegrationTestBase extends MonixBioSuite diff --git a/src/test/scala/wow/doge/http4sdemo/LibraryServiceSpec.scala b/src/it/scala/wow/doge/http4sdemo/LibraryServiceSpec.scala similarity index 100% rename from src/test/scala/wow/doge/http4sdemo/LibraryServiceSpec.scala rename to src/it/scala/wow/doge/http4sdemo/LibraryServiceSpec.scala diff --git a/src/it/scala/wow/doge/http4sdemo/MonixBioSuite.scala b/src/it/scala/wow/doge/http4sdemo/MonixBioSuite.scala new file mode 100644 index 0000000..f071539 --- /dev/null +++ b/src/it/scala/wow/doge/http4sdemo/MonixBioSuite.scala @@ -0,0 +1,35 @@ +package wow.doge.http4sdemo + +import cats.syntax.all._ +import io.odin.consoleLogger +import io.odin.fileLogger +import io.odin.syntax._ +import monix.bio.Task +import monix.execution.Scheduler + +import scala.concurrent.Future +import munit.TestOptions +import cats.effect.Resource +import io.odin.Logger + +trait MonixBioSuite extends munit.TaglessFinalSuite[Task] { + override protected def toFuture[A](f: Task[A]): Future[A] = { + implicit val s = Scheduler.global + f.runToFuture + } + + def loggerFixture(fileName: Option[String] = None)(implicit + enc: sourcecode.Enclosing + ) = + ResourceFixture( + consoleLogger[Task]().withAsync() |+| fileLogger[Task]( + fileName.getOrElse(enc.value.split("#").head + ".log") + ), + ( + options: TestOptions, + value: Logger[Task] + ) => Task(options.name), + (_: Logger[Task]) => Task.unit + ) + +} diff --git a/src/test/scala/wow/doge/http4sdemo/LibraryControllerSpec.scala b/src/test/scala/wow/doge/http4sdemo/LibraryControllerSpec.scala index c8b07fb..dc8946b 100644 --- a/src/test/scala/wow/doge/http4sdemo/LibraryControllerSpec.scala +++ b/src/test/scala/wow/doge/http4sdemo/LibraryControllerSpec.scala @@ -28,12 +28,11 @@ class LibraryControllerSpec extends MonixBioSuite { val date = LocalDateTime.now() - // val logger = consoleLogger[Task]() val Root = Uri(path = "") - test("get books success") { + test("get books success") { import org.http4s.circe.CirceEntityCodec._ val book = Book(1, "book1", "adsgq342dsdc", 1, date) val service = new NoopLibraryService { diff --git a/src/test/scala/wow/doge/http4sdemo/LibrarySpec2.scala b/src/test/scala/wow/doge/http4sdemo/LibrarySpec2.scala deleted file mode 100644 index bb80ee3..0000000 --- a/src/test/scala/wow/doge/http4sdemo/LibrarySpec2.scala +++ /dev/null @@ -1,51 +0,0 @@ -package wow.doge.http4sdemo - -import com.dimafeng.testcontainers.PostgreSQLContainer -import monix.bio.IO -import monix.bio.UIO -import wow.doge.http4sdemo.services.LibraryDbio -import wow.doge.http4sdemo.services.LibraryServiceImpl - -class LibrarySpec2 extends DatabaseIntegrationTestBase { - - override def afterContainersStart(containers: Containers): Unit = { - createSchema(containers) - } - - test("blah") { - withContainers { - case postgresContainer: PostgreSQLContainer => - val io = - withDb(postgresContainer.jdbcUrl)(db => - for { - // _ <- db.runL(Tables.schema.create) - _ <- UIO.unit - service = new LibraryServiceImpl( - profile, - new LibraryDbio(profile), - db - ) - _ <- service - .getBookById(1) - .hideErrors - .flatMap(r => UIO(println(r))) - } yield () - ) - io - case other => - IO.terminate(new Exception(s"Invalid container ${other.toString}")) - } - } - -// override val container: PostgreSQLContainer = PostgreSQLContainer() - -// "PostgreSQL container" should "be started" in { -// Class.forName(container.driverClassName) -// val connection = DriverManager.getConnection( -// container.jdbcUrl, -// container.username, -// container.password -// ) -// // ... -// } -} diff --git a/src/test/scala/wow/doge/http4sdemo/MonixBioSuite.scala b/src/test/scala/wow/doge/http4sdemo/MonixBioSuite.scala index f071539..a510219 100644 --- a/src/test/scala/wow/doge/http4sdemo/MonixBioSuite.scala +++ b/src/test/scala/wow/doge/http4sdemo/MonixBioSuite.scala @@ -1,16 +1,15 @@ package wow.doge.http4sdemo +import scala.concurrent.Future + import cats.syntax.all._ +import io.odin.Logger import io.odin.consoleLogger import io.odin.fileLogger import io.odin.syntax._ import monix.bio.Task import monix.execution.Scheduler - -import scala.concurrent.Future import munit.TestOptions -import cats.effect.Resource -import io.odin.Logger trait MonixBioSuite extends munit.TaglessFinalSuite[Task] { override protected def toFuture[A](f: Task[A]): Future[A] = {