Skip to content

Commit

Permalink
Switch to munit
Browse files Browse the repository at this point in the history
  • Loading branch information
fthomas committed Feb 9, 2023
1 parent 4a8d212 commit b975b92
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 56 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ lazy val cats = myCrossProject("cats")
.settings(
libraryDependencies ++= Seq(
Dependencies.catsCore,
Dependencies.scalatest % Test
Dependencies.munit % Test
)
)

Expand All @@ -68,7 +68,7 @@ lazy val catsJVM = cats.jvm
lazy val core = myCrossProject("core")
.settings(
libraryDependencies ++= Seq(
Dependencies.scalatest % Test
Dependencies.munit % Test
)
)

Expand Down
90 changes: 55 additions & 35 deletions modules/cats/src/test/scala/eu/timepit/statuspage/MakeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,111 @@ import _root_.cats.instances.either._
import eu.timepit.statuspage.cats._
import eu.timepit.statuspage.core.Result.{Error, Info}
import eu.timepit.statuspage.core.plaintext.renderRoot
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import munit.FunSuite

class MakeTest extends AnyFunSuite with Matchers {
class MakeTest extends FunSuite {
type F[A] = Either[String, A]
final val mk = new Make[F, String](identity)

test("mk.root 1") {
mk.root(mk.entryOk("database", Right(0)), mk.entryOk("network", Right(0)))
val obtained = mk
.root(mk.entryOk("database", Right(0)), mk.entryOk("network", Right(0)))
.map(renderRoot)
.getOrElse("") shouldBe
.getOrElse("")
val expected =
s"""|status: OK
|database: OK
|network: OK
""".stripMargin.trim
assertEquals(obtained, expected)
}

test("mk.root 2") {
val msg = "Database is not accessible"
mk.root(mk.entryOk("database", Left(msg)), mk.entryOk("network", Right(0)))
val obtained = mk
.root(mk.entryOk("database", Left(msg)), mk.entryOk("network", Right(0)))
.map(renderRoot)
.getOrElse("") shouldBe
.getOrElse("")
val expected =
s"""|status: ERROR
|database: ERROR $msg
|network: OK
""".stripMargin.trim
assertEquals(obtained, expected)
}

test("mk.root 3") {
mk.root(
mk.group(
"database",
mk.entryInfo("customers", Right("378")),
mk.entryInfo("items", Right("8934748"))
val obtained = mk
.root(
mk.group(
"database",
mk.entryInfo("customers", Right("378")),
mk.entryInfo("items", Right("8934748"))
)
)
).map(renderRoot)
.getOrElse("") shouldBe
.map(renderRoot)
.getOrElse("")
val expected =
s"""|status: OK
|database_status: OK
|database_customers: 378
|database_items: 8934748
""".stripMargin.trim
assertEquals(obtained, expected)
}

test("mk.root 4") {
mk.root(
mk.group(
"database",
mk.entryInfo("customers", Right("378")),
mk.entryInfo("items", Right("8934748"))
),
mk.entryOk("network", Left("timeout"))
).map(renderRoot)
.getOrElse("") shouldBe
val obtained = mk
.root(
mk.group(
"database",
mk.entryInfo("customers", Right("378")),
mk.entryInfo("items", Right("8934748"))
),
mk.entryOk("network", Left("timeout"))
)
.map(renderRoot)
.getOrElse("")
val expected =
s"""|status: ERROR
|database_status: OK
|database_customers: 378
|database_items: 8934748
|network: ERROR timeout
""".stripMargin.trim
assertEquals(obtained, expected)
}

test("mk.root 5") {
mk.root(
mk.entry("database_items", Right(8934748))(i =>
if (i > 100) Info(i.toString)
else Error.withMsg(i.toString)
val obtained = mk
.root(
mk.entry("database_items", Right(8934748))(i =>
if (i > 100) Info(i.toString)
else Error.withMsg(i.toString)
)
)
).map(renderRoot)
.getOrElse("") shouldBe
.map(renderRoot)
.getOrElse("")
val expected =
s"""|status: OK
|database_items: 8934748
""".stripMargin.trim
assertEquals(obtained, expected)
}

test("mk.root 6") {
mk.root(
mk.entry("database_items", Right(42))(i =>
if (i > 100) Info(i.toString)
else Error.withMsg(i.toString)
val obtained = mk
.root(
mk.entry("database_items", Right(42))(i =>
if (i > 100) Info(i.toString) else Error.withMsg(i.toString)
)
)
).map(renderRoot)
.getOrElse("") shouldBe
.map(renderRoot)
.getOrElse("")
val expected =
s"""|status: ERROR
|database_items: ERROR 42
""".stripMargin.trim
assertEquals(obtained, expected)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,43 @@ import eu.timepit.statuspage.core.Item.{Entry, Group, JustShow}
import eu.timepit.statuspage.core.Result.{Error, Info, Ok, Warning}
import eu.timepit.statuspage.core._
import eu.timepit.statuspage.core.plaintext.renderRoot
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import munit.FunSuite

class PlaintextTest extends AnyFunSuite with Matchers {
class PlaintextTest extends FunSuite {
test("renderRoot 1") {
renderRoot(Root(Nil, Ok)) shouldBe "status: OK"
assertEquals(renderRoot(Root(Nil, Ok)), "status: OK")
}

test("renderRoot 2") {
renderRoot(Root(Nil, Error.withoutMsg)) shouldBe "status: ERROR"
assertEquals(renderRoot(Root(Nil, Error.withoutMsg)), "status: ERROR")
}

test("renderRoot 3") {
val msg = "Database is not accessible"
renderRoot(Root(Nil, Error.withMsg(msg))) shouldBe s"status: ERROR $msg"
assertEquals(renderRoot(Root(Nil, Error.withMsg(msg))), s"status: ERROR $msg")
}

test("renderRoot 4") {
renderRoot(Root(List(Entry("database_status", Ok)), Ok)) shouldBe
s"""|status: OK
val obtained = renderRoot(Root(List(Entry("database_status", Ok)), Ok))
val expected = s"""|status: OK
|database_status: OK
""".stripMargin.trim
assertEquals(obtained, expected)
}

test("renderRoot 5") {
renderRoot(
Root(List(Entry("database_status", Ok), Entry("elastic_search_status", Ok)), Ok)
) shouldBe
val obtained =
renderRoot(Root(List(Entry("database_status", Ok), Entry("elastic_search_status", Ok)), Ok))
val expected =
s"""|status: OK
|database_status: OK
|elastic_search_status: OK
""".stripMargin.trim
assertEquals(obtained, expected)
}

test("renderRoot 6") {
renderRoot(
val obtained = renderRoot(
Root(
List(
Group(
Expand All @@ -50,32 +51,38 @@ class PlaintextTest extends AnyFunSuite with Matchers {
),
Ok
)
) shouldBe
)
val expected =
s"""|status: OK
|database_status: OK
|database_customers: 378
|database_items: 8934748
""".stripMargin.trim
assertEquals(obtained, expected)
}

test("renderRoot 7") {
renderRoot(
val obtained = renderRoot(
Root(List(Group("database", List(Group("node1", Nil, Ok), Group("node2", Nil, Ok)), Ok)), Ok)
) shouldBe
)
val expected =
s"""|status: OK
|database_status: OK
|database_node1_status: OK
|database_node2_status: OK
""".stripMargin.trim
assertEquals(obtained, expected)
}

test("renderRoot 8") {
val items = List(Entry("database1", Ok), Entry("database2", Warning.withMsg("slow")))
renderRoot(Root(items, overallOf(items))) shouldBe
val obtained = renderRoot(Root(items, overallOf(items)))
val expected =
s"""|status: WARNING
|database1: OK
|database2: WARNING slow
""".stripMargin.trim
assertEquals(obtained, expected)
}

test("renderRoot 9") {
Expand All @@ -84,22 +91,26 @@ class PlaintextTest extends AnyFunSuite with Matchers {
Entry("database2", Warning.withMsg("slow")),
Entry("database3", Error.withMsg("unavailable"))
)
renderRoot(Root(items, overallOf(items))) shouldBe
val obtained = renderRoot(Root(items, overallOf(items)))
val expected =
s"""|status: ERROR
|database1: OK
|database2: WARNING slow
|database3: ERROR unavailable
""".stripMargin.trim
assertEquals(obtained, expected)
}

test("renderRoot: JustShow") {
val items =
List(Entry("entry1", Ok), JustShow(Entry("entry2", Error.withoutMsg)), Entry("entry3", Ok))
renderRoot(Root(items, overallOf(items))) shouldBe
val obtained = renderRoot(Root(items, overallOf(items)))
val expected =
s"""|status: OK
|entry1: OK
|entry2: ERROR
|entry3: OK
""".stripMargin.trim
assertEquals(obtained, expected)
}
}
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import sbt.stringToOrganization

object Dependencies {
final val catsCore = "org.typelevel" %% "cats-core" % "2.9.0"
final val scalatest = "org.scalatest" %% "scalatest" % "3.2.15"
final val munit = "org.scalameta" %% "munit" % "0.7.29"
}

0 comments on commit b975b92

Please sign in to comment.