temp commit

This commit is contained in:
Rohan Sircar 2021-04-17 23:35:10 +05:30
parent fa0e598602
commit ddb2e45754
9 changed files with 62 additions and 107 deletions

View File

@ -44,6 +44,7 @@ lazy val flyway = (project in file("modules/flyway"))
lazy val root = (project in file(".")) lazy val root = (project in file("."))
.enablePlugins(CodegenPlugin, DockerPlugin, JavaAppPackaging, AshScriptPlugin) .enablePlugins(CodegenPlugin, DockerPlugin, JavaAppPackaging, AshScriptPlugin)
.configs(IntegrationTest)
.settings( .settings(
organization := "wow.doge", organization := "wow.doge",
name := "http4s-demo", name := "http4s-demo",
@ -58,6 +59,7 @@ lazy val root = (project in file("."))
dockerBaseImage := dockerJavaImage, dockerBaseImage := dockerJavaImage,
dockerExposedPorts := Seq(8081), dockerExposedPorts := Seq(8081),
dockerUsername := Some("rohansircar"), dockerUsername := Some("rohansircar"),
Defaults.itSettings,
scalacOptions ++= Seq( scalacOptions ++= Seq(
"-encoding", "-encoding",
"UTF-8", "UTF-8",
@ -85,8 +87,8 @@ lazy val root = (project in file("."))
"org.http4s" %% "http4s-circe" % Http4sVersion, "org.http4s" %% "http4s-circe" % Http4sVersion,
"org.http4s" %% "http4s-dsl" % Http4sVersion, "org.http4s" %% "http4s-dsl" % Http4sVersion,
"io.circe" %% "circe-generic" % CirceVersion, "io.circe" %% "circe-generic" % CirceVersion,
"org.scalameta" %% "munit" % MunitVersion % Test, "org.scalameta" %% "munit" % MunitVersion % "it,test",
"org.typelevel" %% "munit-cats-effect-2" % MunitCatsEffectVersion % Test, "org.typelevel" %% "munit-cats-effect-2" % MunitCatsEffectVersion % "it,test",
"ch.qos.logback" % "logback-classic" % LogbackVersion, "ch.qos.logback" % "logback-classic" % LogbackVersion,
"org.scalameta" %% "svm-subs" % "20.2.0", "org.scalameta" %% "svm-subs" % "20.2.0",
"co.fs2" %% "fs2-reactive-streams" % "2.5.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.rms.miu" %% "slick-cats" % "0.10.4",
"com.kubukoz" %% "slick-effect" % "0.3.0", "com.kubukoz" %% "slick-effect" % "0.3.0",
"io.circe" %% "circe-fs2" % "0.13.0", "io.circe" %% "circe-fs2" % "0.13.0",
// "org.scalameta" %% "munit" % "0.7.23" % Test, // "org.scalameta" %% "munit" % "0.7.23" % "it,test",
"de.lolhens" %% "munit-tagless-final" % "0.0.1" % Test, "de.lolhens" %% "munit-tagless-final" % "0.0.1" % "it,test",
"org.scalameta" %% "munit-scalacheck" % "0.7.23" % Test, "org.scalameta" %% "munit-scalacheck" % "0.7.23" % "it,test",
"org.scalacheck" %% "scalacheck" % "1.15.3" % Test, "org.scalacheck" %% "scalacheck" % "1.15.3" % "it,test",
"com.dimafeng" %% "testcontainers-scala-munit" % "0.39.3" % Test, "com.dimafeng" %% "testcontainers-scala-munit" % "0.39.3" % IntegrationTest,
"com.dimafeng" %% "testcontainers-scala-postgresql" % "0.39.3" % Test "com.dimafeng" %% "testcontainers-scala-postgresql" % "0.39.3" % IntegrationTest
), ),
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3"), addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3"),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"), addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.4.3", testFrameworks += new TestFramework("munit.Framework")
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
}
) )
.settings( .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, slickCodegenDatabaseUrl := databaseUrl,
slickCodegenDatabaseUser := databaseUser, slickCodegenDatabaseUser := databaseUser,
slickCodegenDatabasePassword := databasePassword, slickCodegenDatabasePassword := databasePassword,
@ -200,3 +163,12 @@ lazy val root = (project in file("."))
sourceGenerators in Compile += slickCodegen.taskValue sourceGenerators in Compile += slickCodegen.taskValue
) )
.dependsOn(flyway) .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
)
)

View File

@ -1,4 +1,4 @@
{ {
"schemaVersion": 2, "schemaVersion": 2,
"imageName": "rohansircar/http4s-demo:0.0.1" "imageName": "rohansircar/http4s-demo:latest"
} }

View File

@ -1,6 +1,5 @@
// addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.14") // addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.14")
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1") addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
// https://github.com/tototoshi/sbt-slick-codegen // https://github.com/tototoshi/sbt-slick-codegen
libraryDependencies += "com.h2database" % "h2" % "1.4.196" 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.typesafe.sbt" % "sbt-native-packager" % "1.8.0")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1") addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")

View File

@ -11,6 +11,7 @@ import monix.execution.Scheduler
import org.testcontainers.utility.DockerImageName import org.testcontainers.utility.DockerImageName
import slick.jdbc.JdbcBackend import slick.jdbc.JdbcBackend
import slick.jdbc.PostgresProfile import slick.jdbc.PostgresProfile
import wow.doge.http4sdemo.MonixBioSuite
trait DatabaseIntegrationTestBase trait DatabaseIntegrationTestBase
extends MonixBioSuite extends MonixBioSuite

View File

@ -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
)
}

View File

@ -28,12 +28,11 @@ class LibraryControllerSpec extends MonixBioSuite {
val date = LocalDateTime.now() val date = LocalDateTime.now()
// val logger = consoleLogger[Task]() // val logger = consoleLogger[Task]()
val Root = Uri(path = "") val Root = Uri(path = "")
test("get books success") { test("get books success") {
import org.http4s.circe.CirceEntityCodec._ import org.http4s.circe.CirceEntityCodec._
val book = Book(1, "book1", "adsgq342dsdc", 1, date) val book = Book(1, "book1", "adsgq342dsdc", 1, date)
val service = new NoopLibraryService { val service = new NoopLibraryService {

View File

@ -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
// )
// // ...
// }
}

View File

@ -1,16 +1,15 @@
package wow.doge.http4sdemo package wow.doge.http4sdemo
import scala.concurrent.Future
import cats.syntax.all._ import cats.syntax.all._
import io.odin.Logger
import io.odin.consoleLogger import io.odin.consoleLogger
import io.odin.fileLogger import io.odin.fileLogger
import io.odin.syntax._ import io.odin.syntax._
import monix.bio.Task import monix.bio.Task
import monix.execution.Scheduler import monix.execution.Scheduler
import scala.concurrent.Future
import munit.TestOptions import munit.TestOptions
import cats.effect.Resource
import io.odin.Logger
trait MonixBioSuite extends munit.TaglessFinalSuite[Task] { trait MonixBioSuite extends munit.TaglessFinalSuite[Task] {
override protected def toFuture[A](f: Task[A]): Future[A] = { override protected def toFuture[A](f: Task[A]): Future[A] = {