From fa5f885f87a985d06cc3a249487479e97b60e512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20Mickevi=C4=8Dius?= Date: Wed, 26 May 2021 19:55:49 +0300 Subject: [PATCH] Switch to munit and latest ciris --- README.md | 13 +++--- build.sbt | 10 ++--- project/plugins.sbt | 2 +- src/test/scala/HoconSpec.scala | 82 ++++++++++++++++------------------ 4 files changed, 51 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 57fdc8b..fba502a 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Or a snapshot from a [snapshot repository](https://oss.sonatype.org/content/repo |------------|-------------|------------| | 0.1 | 2.12 | 0.12.1 | | 0.2.1 | 2.13 | 0.13.0-RC1 | -| 1.0.0 | 2.13, 3 | 2.0.0-RC3 | +| 1.0.0 | 2.13, 3 | 2.0.0 | ## Example usage @@ -37,7 +37,6 @@ import java.time.Period import scala.concurrent.duration._ import cats.effect.IO -import cats.effect.unsafe.implicits.global import cats.implicits._ import com.typesafe.config.ConfigFactory @@ -54,12 +53,12 @@ val config = ConfigFactory.parseString(""" case class Rate(elements: Int, burstDuration: FiniteDuration, checkInterval: Period) val hocon = hoconAt(config)("rate") -val rate = ( +( hocon("elements").as[Int], hocon("burst-duration").as[FiniteDuration], hocon("check-interval").as[Period] -).parMapN(Rate.apply).load[IO].unsafeRunSync() - -rate.burstDuration shouldBe 100.millis -rate.checkInterval shouldBe Period.ofWeeks(2) +).parMapN(Rate.apply).load[IO].map { rate => + assertEquals(rate.burstDuration, 100.millis) + assertEquals(rate.checkInterval, Period.ofWeeks(2)) +} ``` diff --git a/build.sbt b/build.sbt index b772efd..92dbc3e 100644 --- a/build.sbt +++ b/build.sbt @@ -3,13 +3,13 @@ name := "ciris-hocon" description := "Provides HOCON configuration source for Ciris" scalaVersion := "2.13.6" -crossScalaVersions += "3.0.0-RC3" +crossScalaVersions += "3.0.0" libraryDependencies ++= Seq( - "is.cir" %% "ciris" % "2.0.0-RC3", - "com.typesafe" % "config" % "1.4.1", - "org.scalatest" %% "scalatest" % "3.2.8" % "test", - "org.typelevel" %% "cats-effect" % "3.1.0" % "test" + "is.cir" %% "ciris" % "2.0.0", + "com.typesafe" % "config" % "1.4.1", + "org.typelevel" %% "munit-cats-effect-3" % "1.0.3" % "test", + "org.typelevel" %% "cats-effect" % "3.1.1" % "test" ) scalafmtOnCompile := true diff --git a/project/plugins.sbt b/project/plugins.sbt index db73e07..324fc7f 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,4 +4,4 @@ addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.28") addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.18") addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0") addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7") -addSbtPlugin("io.github.zamblauskas" % "sbt-examplestest" % "0.2.3") +addSbtPlugin("io.github.zamblauskas" % "sbt-examplestest" % "0.3.0") diff --git a/src/test/scala/HoconSpec.scala b/src/test/scala/HoconSpec.scala index f078313..dc0a683 100644 --- a/src/test/scala/HoconSpec.scala +++ b/src/test/scala/HoconSpec.scala @@ -18,13 +18,9 @@ import scala.concurrent.duration._ import cats.effect.IO import com.typesafe.config.ConfigFactory -import org.scalatest.EitherValues -import org.scalatest.matchers.should.Matchers -import org.scalatest.wordspec.AnyWordSpec - -class HoconSpec extends AnyWordSpec with Matchers with EitherValues { - import cats.effect.unsafe.implicits.global +import munit.CatsEffectSuite +class HoconSpec extends CatsEffectSuite { import lt.dvim.ciris.Hocon._ private val config = ConfigFactory.parseString(""" @@ -41,42 +37,42 @@ class HoconSpec extends AnyWordSpec with Matchers with EitherValues { private val hocon = hoconAt(config)("nested.config") - "ciris-hocon" should { - "parse Int" in { - hocon("int").as[Int].load[IO].unsafeRunSync() shouldBe 2 - } - "parse String" in { - hocon("str").as[String].load[IO].unsafeRunSync() shouldBe "labas" - } - "parse Duration" in { - hocon("dur").as[java.time.Duration].load[IO].unsafeRunSync() shouldBe java.time.Duration.ofMillis(10) - hocon("dur").as[FiniteDuration].load[IO].unsafeRunSync() shouldBe 10.millis - } - "parse Boolean" in { - hocon("bool").as[Boolean].load[IO].unsafeRunSync() shouldBe true - } - "parse Period" in { - hocon("per").as[java.time.Period].load[IO].unsafeRunSync() shouldBe java.time.Period.ofWeeks(2) - } - "handle missing" in { - hocon("missing") - .as[Int] - .attempt[IO] - .unsafeRunSync() - .left - .value - .messages - .toList should contain("Missing nested.config.missing") - } - "handle decode error" in { - hocon("str") - .as[Int] - .attempt[IO] - .unsafeRunSync() - .left - .value - .messages - .toList should contain("Nested.config.str with value labas cannot be converted to Int") - } + test("parse Int") { + hocon("int").as[Int].load[IO] assertEquals 2 + } + test("parse String") { + hocon("str").as[String].load[IO] assertEquals "labas" + } + test("parse java Duration") { + hocon("dur").as[java.time.Duration].load[IO] assertEquals java.time.Duration.ofMillis(10) + } + test("parse scala Duration") { + hocon("dur").as[FiniteDuration].load[IO] assertEquals 10.millis + } + test("parse Boolean") { + hocon("bool").as[Boolean].load[IO] assertEquals true + } + test("parse Period") { + hocon("per").as[java.time.Period].load[IO] assertEquals java.time.Period.ofWeeks(2) + } + test("handle missing") { + hocon("missing") + .as[Int] + .attempt[IO] + .map { + case Left(err) => err.messages.toList.head + case Right(_) => "config loaded" + } + .assertEquals("Missing nested.config.missing") + } + test("handle decode error") { + hocon("str") + .as[Int] + .attempt[IO] + .map { + case Left(err) => err.messages.toList.head + case Right(_) => "config loaded" + } + .assertEquals("Nested.config.str with value labas cannot be converted to Int") } }