Skip to content

Commit

Permalink
Introduce munit-cats-effect (#4522)
Browse files Browse the repository at this point in the history
* Introduce munit-cats-effect

* Use standard MUnit Cats Effect suite / assertions
  • Loading branch information
shinyhappydan authored Nov 24, 2023
1 parent 0010827 commit 96174df
Show file tree
Hide file tree
Showing 111 changed files with 725 additions and 996 deletions.
7 changes: 7 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ val logbackVersion = "1.4.11"
val magnoliaVersion = "1.1.6"
val mockitoVersion = "1.17.29"
val munitVersion = "1.0.0-M10"
val munitCatsEffectVersion = "2.0.0-M4"
val nimbusJoseJwtVersion = "9.37.1"
val postgresJdbcVersion = "42.6.0"
val pureconfigVersion = "0.17.4"
Expand Down Expand Up @@ -111,6 +112,7 @@ lazy val logback = "ch.qos.logback" % "logback-classic
lazy val magnolia = "com.softwaremill.magnolia1_2" %% "magnolia" % magnoliaVersion
lazy val mockito = "org.mockito" %% "mockito-scala" % mockitoVersion
lazy val munit = "org.scalameta" %% "munit" % munitVersion
lazy val munitCatsEffect = "org.typelevel" %% "munit-cats-effect" % munitCatsEffectVersion
lazy val nimbusJoseJwt = "com.nimbusds" % "nimbus-jose-jwt" % nimbusJoseJwtVersion
lazy val pureconfig = "com.github.pureconfig" %% "pureconfig" % pureconfigVersion
lazy val pureconfigCats = "com.github.pureconfig" %% "pureconfig-cats" % pureconfigVersion
Expand Down Expand Up @@ -217,6 +219,7 @@ lazy val kernel = project
pureconfig,
pureconfigCats,
munit % Test,
munitCatsEffect % Test,
scalaTest % Test
),
addCompilerPlugin(kindProjector),
Expand All @@ -240,6 +243,7 @@ lazy val testkit = project
catsRetry,
doobiePostgres,
munit,
munitCatsEffect,
scalaTest,
testContainers
) ++ doobie,
Expand All @@ -262,6 +266,7 @@ lazy val sourcingPsql = project
classgraph,
distageCore,
munit % Test,
munitCatsEffect % Test,
catsEffectLaws % Test,
logback % Test
) ++ doobie,
Expand Down Expand Up @@ -320,6 +325,7 @@ lazy val sdk = project
akkaTestKitTyped % Test,
akkaHttpTestKit % Test,
munit % Test,
munitCatsEffect % Test,
scalaTest % Test
),
addCompilerPlugin(kindProjector),
Expand Down Expand Up @@ -764,6 +770,7 @@ lazy val storage = project
akkaTestKit % Test,
mockito % Test,
munit % Test,
munitCatsEffect % Test,
scalaTest % Test
),
cleanFiles ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import ch.epfl.bluebrain.nexus.delta.sdk.plugin.PluginDef
import ch.epfl.bluebrain.nexus.delta.sourcing.postgres.Doobie._
import ch.epfl.bluebrain.nexus.delta.wiring.DeltaModule
import ch.epfl.bluebrain.nexus.testkit.elasticsearch.ElasticSearchContainer
import ch.epfl.bluebrain.nexus.testkit.mu.ce.ResourceFixture
import ch.epfl.bluebrain.nexus.testkit.mu.ce.CatsEffectSuite
import ch.epfl.bluebrain.nexus.testkit.mu.ce.ResourceFixture.IOFixture
import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite
import ch.epfl.bluebrain.nexus.testkit.postgres.PostgresContainer
import com.typesafe.config.impl.ConfigImpl
import izumi.distage.model.definition.{Module, ModuleDef}
import izumi.distage.model.plan.Roots
import izumi.distage.planning.solver.PlanVerifier
import munit.AnyFixture
import munit.{AnyFixture, CatsEffectSuite}
import munit.catseffect.IOFixture

import java.nio.file.{Files, Paths}

Expand All @@ -25,7 +24,7 @@ import java.nio.file.{Files, Paths}
* - HOCON configuration files match their classes counterpart
* - Distage wiring is valid
*/
class MainSuite extends CatsEffectSuite with MainSuite.Fixture {
class MainSuite extends NexusSuite with MainSuite.Fixture {

private val pluginsParentPath = Paths.get("target/plugins").toAbsolutePath
private val pluginLoaderConfig = PluginLoaderConfig(pluginsParentPath.toString)
Expand Down Expand Up @@ -127,7 +126,7 @@ object MainSuite {
_ <- Resource.make(acquire(postgres, elastic))(_ => release)
} yield ()

val main: IOFixture[Unit] = ResourceFixture.suiteLocal("main", resource())
val main: IOFixture[Unit] = ResourceSuiteLocalFixture("main", resource())

}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ch.epfl.bluebrain.nexus.delta.kernel.utils

import ch.epfl.bluebrain.nexus.delta.kernel.utils.ClasspathResourceError.{InvalidJson, InvalidJsonObject}
import io.circe.syntax._
import io.circe.{Json, JsonObject}
import munit.CatsEffectSuite

class ClasspathResourceLoaderSuite extends CatsEffectSuite {
private val loader: ClasspathResourceLoader = ClasspathResourceLoader()

test("return the path") {
loader.absolutePath("resource.txt").assert(_.endsWith("resource.txt"))
}

test("return the contents of a handlebar template") {
loader
.contentOf("resource.txt", "value" -> "v")
.assertEquals("A text resource with replacement 'v'")
}

test("return the contents of a handlebar template, multiple times") {
val io = loader.contentOf("resource.txt", "value" -> "v")

for {
_ <- io.assertEquals("A text resource with replacement 'v'")
_ <- io.assertEquals("A text resource with replacement 'v'")
} yield {
()
}
}

test("return the contents of a handlebar template as json") {
loader
.jsonContentOf("resource.json", "value" -> "v")
.assertEquals(Json.obj("k" -> "v".asJson))
}

test("fail when a file cannot be parsed as json") {
loader
.jsonContentOf("resource.txt", "value" -> "v")
.intercept[InvalidJson]
}

test("return the contaents of a handlebar template as a json object") {
loader
.jsonObjectContentOf("resource.json", "value" -> "v")
.assertEquals(JsonObject("k" -> "v".asJson))
}

test("fail when a file contains JSON but is not a json object") {
loader
.jsonObjectContentOf("resource-json-array.json")
.intercept[InvalidJsonObject]
.assertEquals(
InvalidJsonObject("resource-json-array.json")
)
}

test("fail when a resource does not exist") {
loader
.contentOf("resource2.txt", "value" -> "v")
.intercept[Throwable]
.assert(e => e.getMessage.contains("not found") && e.getMessage.contains("resource2.txt"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import ch.epfl.bluebrain.nexus.delta.sdk.model.BaseUri
import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContextDummy
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{Label, ResourceRef}
import ch.epfl.bluebrain.nexus.testkit.mu.ce.CatsEffectSuite
import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite

class FileSelfSuite extends CatsEffectSuite {
class FileSelfSuite extends NexusSuite {

implicit private val baseUri: BaseUri = BaseUri("http://bbp.epfl.ch", Label.unsafe("v1"))

Expand Down Expand Up @@ -53,26 +53,26 @@ class FileSelfSuite extends CatsEffectSuite {

test("A relative self should not be parsed") {
val input = iri"/$org/$project/$compactResourceId"
fileSelf.parse(input).intercept(NonAbsoluteLink(input))
fileSelf.parse(input).interceptEquals(NonAbsoluteLink(input))
}

test("A self from an external website should not be parsed") {
val input = iri"http://localhost/v1/files/$org/$project/$compactResourceId"
fileSelf.parse(input).intercept(ExternalLink(input))
fileSelf.parse(input).interceptEquals(ExternalLink(input))
}

test("A self with an incorrect path should not be parsed") {
val input = iri"http://bbp.epfl.ch/v1/files/$org/$project/$compactResourceId/extra"
fileSelf.parse(input).intercept(InvalidPath(input))
fileSelf.parse(input).interceptEquals(InvalidPath(input))
}

test("A self with an incorrect project label should not be parsed") {
val input = iri"http://bbp.epfl.ch/v1/files/%illegal/$project/$compactResourceId"
fileSelf.parse(input).intercept(InvalidProject(input))
fileSelf.parse(input).interceptEquals(InvalidProject(input))
}

test("A self with an incorrect id should not resolve") {
val input = iri"""http://bbp.epfl.ch/v1/files/$org/$project/badcurie:$compactResourceId")}"""
fileSelf.parse(input).intercept(InvalidFileId(input))
fileSelf.parse(input).interceptEquals(InvalidFileId(input))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import cats.effect.{IO, Resource}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.BlazegraphClient
import ch.epfl.bluebrain.nexus.delta.sdk.http.HttpClientSetup
import ch.epfl.bluebrain.nexus.testkit.blazegraph.BlazegraphContainer
import ch.epfl.bluebrain.nexus.testkit.mu.ce.ResourceFixture
import ch.epfl.bluebrain.nexus.testkit.mu.ce.ResourceFixture.IOFixture
import munit.CatsEffectSuite
import munit.catseffect.IOFixture

import scala.concurrent.duration._

Expand All @@ -30,14 +30,9 @@ object BlazegraphClientSetup extends Fixtures {
}
}

def suiteLocalFixture(
name: String
): IOFixture[BlazegraphClient] =
ResourceFixture.suiteLocal(name, resource())

trait Fixture {
val blazegraphClient: ResourceFixture.IOFixture[BlazegraphClient] =
BlazegraphClientSetup.suiteLocalFixture("blazegraphClient")
trait Fixture { self: CatsEffectSuite =>
val blazegraphClient: IOFixture[BlazegraphClient] =
ResourceSuiteLocalFixture("blazegraphClient", resource())
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import ch.epfl.bluebrain.nexus.delta.sdk.views.ViewRef
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Subject}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
import ch.epfl.bluebrain.nexus.delta.sourcing.query.SelectFilter
import ch.epfl.bluebrain.nexus.testkit.mu.ce.CatsEffectSuite
import fs2.Stream
import cats.effect.Ref
import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite

class BlazegraphDeletionTaskSuite extends CatsEffectSuite {
class BlazegraphDeletionTaskSuite extends NexusSuite {

implicit private val subject: Subject = Anonymous

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.query.SelectFilter
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.Elem.{DroppedElem, FailedElem, SuccessElem}
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.ProjectionErr.CouldNotFindPipeErr
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.{NoopSink, PipeChain, PipeRef}
import ch.epfl.bluebrain.nexus.testkit.mu.ce.{CatsEffectSuite, PatienceConfig}
import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite
import ch.epfl.bluebrain.nexus.testkit.mu.ce.PatienceConfig
import fs2.Stream

import java.time.Instant
import scala.concurrent.duration._

class BlazegraphIndexingActionSuite extends CatsEffectSuite with Fixtures {
class BlazegraphIndexingActionSuite extends NexusSuite with Fixtures {

implicit private val patienceConfig: PatienceConfig = PatienceConfig(5.seconds, 10.millis)

Expand Down
Loading

0 comments on commit 96174df

Please sign in to comment.