Skip to content

Commit

Permalink
Switch to munit and latest ciris
Browse files Browse the repository at this point in the history
  • Loading branch information
2m committed May 28, 2021
1 parent b95cb6b commit 2f477bf
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 55 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))
}
```
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
82 changes: 39 additions & 43 deletions src/test/scala/HoconSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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("""
Expand All @@ -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")
}
}

0 comments on commit 2f477bf

Please sign in to comment.