Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FS2 io utilities to load classpath resources #4518

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ lazy val kernel = project
caffeine,
catsCore,
catsRetry,
catsEffect,
fs2,
fs2io,
circeCore,
circeParser,
handleBars,
Expand Down Expand Up @@ -258,8 +261,6 @@ lazy val sourcingPsql = project
circeParser,
classgraph,
distageCore,
fs2,
fs2io,
munit % Test,
catsEffectLaws % Test,
logback % Test
Expand Down Expand Up @@ -316,7 +317,6 @@ lazy val sdk = project
circeLiteral,
circeGenericExtras,
distageCore,
fs2,
akkaTestKitTyped % Test,
akkaHttpTestKit % Test,
munit % Test,
Expand Down Expand Up @@ -792,7 +792,6 @@ lazy val tests = project
akkaStream,
circeOptics,
circeGenericExtras,
fs2,
logback,
akkaTestKit % Test,
akkaHttpTestKit % Test,
Expand Down Expand Up @@ -1052,14 +1051,22 @@ val staticAnalysis =

addCommandAlias("static-analysis", staticAnalysis)

def unitTestsWithCoverageCommandsForModules(modules: List[String]) = {
def runTestsWithCoverageCommandsForModules(modules: List[String]) = {
";coverage" +
modules.map(module => s";$module/test").mkString +
modules.map(module => s";$module/coverageReport").mkString
}
addCommandAlias("core-unit-tests-with-coverage", unitTestsWithCoverageCommandsForModules(coreModules))
addCommandAlias("app-unit-tests-with-coverage", unitTestsWithCoverageCommandsForModules(List("app")))
addCommandAlias("plugins-unit-tests-with-coverage", unitTestsWithCoverageCommandsForModules(List("plugins")))
def runTestsCommandsForModules(modules: List[String]) = {
modules.map(module => s";$module/test").mkString
}

addCommandAlias("core-unit-tests", runTestsCommandsForModules(coreModules))
addCommandAlias("core-unit-tests-with-coverage", runTestsWithCoverageCommandsForModules(coreModules))
addCommandAlias("app-unit-tests", runTestsCommandsForModules(List("app")))
addCommandAlias("app-unit-tests-with-coverage", runTestsWithCoverageCommandsForModules(List("app")))
addCommandAlias("plugins-unit-tests", runTestsCommandsForModules(List("plugins")))
addCommandAlias("plugins-unit-tests-with-coverage", runTestsWithCoverageCommandsForModules(List("plugins")))
addCommandAlias("integration-tests", runTestsCommandsForModules(List("tests")))

// This option allows distage 1.0.10 to run on JDK 17+
val cglibFix = "--add-opens=java.base/java.lang=ALL-UNNAMED"
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class DeltaModule(appCfg: AppConfig, config: Config)(implicit classLoader: Class
.merge(otherCtxResolutions.toSeq: _*)
}

make[JsonLdApi].from { () =>
make[JsonLdApi].fromValue {
new JsonLdJavaApi(appCfg.jsonLdApi)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AppConfigSpec extends CatsEffectSpec with BeforeAndAfterAll {

"AppConfig" should {

val externalConfigPath = loader.absolutePath("/config/external.conf").accepted
val externalConfigPath = loader.absolutePath("config/external.conf").accepted

"load conf" in {
val (conf, _) = AppConfig.load().accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class AclsRoutesSpec extends BaseRouteSpec {
val meta = aclMetadata(acl.address, rev, createdBy = user, updatedBy = user).removeKeys(keywords.context)
aclJson(acl) deepMerge meta
}
jsonContentOf("/acls/acls-route-response.json", "total" -> total) deepMerge
Json.obj("_results" -> Json.fromValues(results))
jsonContentOf("acls/acls-route-response.json", "total" -> total) deepMerge
Json.obj("_results" -> Json.fromValues(results))
}

private val identities = IdentitiesDummy(caller)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ class EventsRoutesSpec extends BaseRouteSpec with IOFromMap {
"get the events stream for all events" in {
Get("/v1/events") ~> asAlice ~> routes ~> check {
mediaType shouldBe MediaTypes.`text/event-stream`
chunksStream.asString(5).strip shouldEqual contentOf("/events/eventstream-0-5.txt").strip
chunksStream.asString(5).strip shouldEqual contentOf("events/eventstream-0-5.txt").strip
}
}

"get the acl events" in {
Get("/v1/acl/events") ~> asAlice ~> routes ~> check {
mediaType shouldBe MediaTypes.`text/event-stream`
chunksStream.asString(2).strip shouldEqual contentOf("/events/acl-events.txt").strip
chunksStream.asString(2).strip shouldEqual contentOf("events/acl-events.txt").strip
}
}

Expand All @@ -186,7 +186,7 @@ class EventsRoutesSpec extends BaseRouteSpec with IOFromMap {
forAll(endpoints) { endpoint =>
Get(endpoint) ~> `Last-Event-ID`("3") ~> asAlice ~> routes ~> check {
mediaType shouldBe MediaTypes.`text/event-stream`
chunksStream.asString(1).strip shouldEqual contentOf("/events/project-events.txt").strip
chunksStream.asString(1).strip shouldEqual contentOf("events/project-events.txt").strip
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class IdentitiesRoutesSpec extends BaseRouteSpec {
"return anonymous" in {
Get("/v1/identities") ~> Accept(`*/*`) ~> route ~> check {
status shouldEqual StatusCodes.OK
response.asJson should equalIgnoreArrayOrder(jsonContentOf("/identities/anonymous.json"))
response.asJson should equalIgnoreArrayOrder(jsonContentOf("identities/anonymous.json"))
}
}

"return all identities" in {
Get("/v1/identities") ~> Accept(`*/*`) ~> addCredentials(OAuth2BearerToken("alice")) ~> route ~> check {
status shouldEqual StatusCodes.OK
response.asJson should equalIgnoreArrayOrder(jsonContentOf("/identities/alice.json"))
response.asJson should equalIgnoreArrayOrder(jsonContentOf("identities/alice.json"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class OrganizationsRoutesSpec extends BaseRouteSpec with IOFromMap {
private val org1CreatedMeta = orgMetadata(org1.label, fixedUuid)

private val org1Created = jsonContentOf(
"/organizations/org-resource.json",
"organizations/org-resource.json",
"label" -> org1.label.value,
"uuid" -> fixedUuid.toString,
"description" -> org1.description.value
Expand All @@ -74,7 +74,7 @@ class OrganizationsRoutesSpec extends BaseRouteSpec with IOFromMap {
private val org2CreatedMeta = orgMetadata(org2.label, fixedUuid, createdBy = alice, updatedBy = alice)

private val org2Created = jsonContentOf(
"/organizations/org-resource.json",
"organizations/org-resource.json",
"label" -> org2.label.value,
"uuid" -> fixedUuid.toString
).removeKeys("description") deepMerge org2CreatedMeta.removeKeys("@context")
Expand Down Expand Up @@ -154,14 +154,14 @@ class OrganizationsRoutesSpec extends BaseRouteSpec with IOFromMap {

Put("/v1/orgs/org1", input.toEntity) ~> routes ~> check {
status shouldEqual StatusCodes.Conflict
response.asJson shouldEqual jsonContentOf("/organizations/already-exists.json", "org" -> org1.label.value)
response.asJson shouldEqual jsonContentOf("organizations/already-exists.json", "org" -> org1.label.value)
}
}

"fail fetching an organization by label and rev when rev is invalid" in {
Get("/v1/orgs/org1?rev=4") ~> routes ~> check {
status shouldEqual StatusCodes.NotFound
response.asJson shouldEqual jsonContentOf("/errors/revision-not-found.json", "provided" -> 4, "current" -> 2)
response.asJson shouldEqual jsonContentOf("errors/revision-not-found.json", "provided" -> 4, "current" -> 2)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ class ProjectsRoutesSpec extends BaseRouteSpec with IOFromMap {
val base = "https://localhost/base/"
val vocab = "https://localhost/voc/"

val payload = jsonContentOf("/projects/create.json", "description" -> desc, "base" -> base, "vocab" -> vocab)
val payload = jsonContentOf("projects/create.json", "description" -> desc, "base" -> base, "vocab" -> vocab)

val payloadUpdated =
jsonContentOf("/projects/create.json", "description" -> "New description", "base" -> base, "vocab" -> vocab)
jsonContentOf("projects/create.json", "description" -> "New description", "base" -> base, "vocab" -> vocab)

val anotherPayload = jsonContentOf("/projects/create.json", "description" -> desc)
val anotherPayload = jsonContentOf("projects/create.json", "description" -> desc)

"A project route" should {

Expand Down Expand Up @@ -177,7 +177,7 @@ class ProjectsRoutesSpec extends BaseRouteSpec with IOFromMap {
Put("/v1/projects/org1/proj", payload.toEntity) ~> routes ~> check {
status shouldEqual StatusCodes.Conflict
response.asJson shouldEqual jsonContentOf(
"/projects/errors/already-exists.json",
"projects/errors/already-exists.json",
"org" -> "org1",
"proj" -> "proj"
)
Expand All @@ -187,7 +187,7 @@ class ProjectsRoutesSpec extends BaseRouteSpec with IOFromMap {
"reject the creation of a project on a deprecated organization" in {
Put("/v1/projects/org2/proj3", payload.toEntity) ~> routes ~> check {
status shouldEqual StatusCodes.BadRequest
response.asJson shouldEqual jsonContentOf("/projects/errors/org-deprecated.json")
response.asJson shouldEqual jsonContentOf("projects/errors/org-deprecated.json")
}
}

Expand Down Expand Up @@ -226,7 +226,7 @@ class ProjectsRoutesSpec extends BaseRouteSpec with IOFromMap {
Put("/v1/projects/org1/proj?rev=42", payloadUpdated.toEntity) ~> routes ~> check {
status shouldEqual StatusCodes.Conflict
response.asJson should equalIgnoreArrayOrder(
jsonContentOf("/projects/errors/incorrect-rev.json", "provided" -> 42, "expected" -> 2)
jsonContentOf("projects/errors/incorrect-rev.json", "provided" -> 42, "expected" -> 2)
)
}
}
Expand All @@ -252,23 +252,23 @@ class ProjectsRoutesSpec extends BaseRouteSpec with IOFromMap {
"reject the deprecation of a project without rev" in {
Delete("/v1/projects/org1/proj") ~> routes ~> check {
status shouldEqual StatusCodes.BadRequest
response.asJson shouldEqual jsonContentOf("/errors/missing-query-param.json", "field" -> "rev")
response.asJson shouldEqual jsonContentOf("errors/missing-query-param.json", "field" -> "rev")
}
}

"reject the deprecation of a already deprecated project" in {
Delete("/v1/projects/org1/proj?rev=3") ~> routes ~> check {
status shouldEqual StatusCodes.BadRequest
response.asJson shouldEqual jsonContentOf(
"/projects/errors/project-deprecated.json",
"projects/errors/project-deprecated.json",
"org" -> "org1",
"proj" -> "proj"
)
}
}

val fetchProjRev2 = jsonContentOf(
"/projects/fetch.json",
"projects/fetch.json",
"org" -> "org1",
"proj" -> "proj",
"orgUuid" -> orgUuid,
Expand All @@ -282,7 +282,7 @@ class ProjectsRoutesSpec extends BaseRouteSpec with IOFromMap {
)

val fetchProjRev3 = jsonContentOf(
"/projects/fetch.json",
"projects/fetch.json",
"org" -> "org1",
"proj" -> "proj",
"orgUuid" -> orgUuid,
Expand All @@ -296,7 +296,7 @@ class ProjectsRoutesSpec extends BaseRouteSpec with IOFromMap {
)

val fetchProj2 = jsonContentOf(
"/projects/fetch.json",
"projects/fetch.json",
"org" -> "org1",
"proj" -> "proj2",
"orgUuid" -> orgUuid,
Expand Down Expand Up @@ -360,7 +360,7 @@ class ProjectsRoutesSpec extends BaseRouteSpec with IOFromMap {
Get("/v1/projects/org1/proj?rev=42") ~> routes ~> check {
status shouldEqual StatusCodes.NotFound
response.asJson shouldEqual jsonContentOf(
"/errors/revision-not-found.json",
"errors/revision-not-found.json",
"provided" -> 42,
"current" -> 3
)
Expand All @@ -371,7 +371,7 @@ class ProjectsRoutesSpec extends BaseRouteSpec with IOFromMap {
Get(s"/v1/projects/$orgUuid/$projectUuid?rev=42") ~> routes ~> check {
status shouldEqual StatusCodes.NotFound
response.asJson shouldEqual jsonContentOf(
"/errors/revision-not-found.json",
"errors/revision-not-found.json",
"provided" -> 42,
"current" -> 3
)
Expand All @@ -388,7 +388,7 @@ class ProjectsRoutesSpec extends BaseRouteSpec with IOFromMap {
"fetch an unknown project" in {
Get(s"/v1/projects/org1/unknown") ~> routes ~> check {
status shouldEqual StatusCodes.NotFound
response.asJson shouldEqual jsonContentOf("/projects/errors/project-not-found.json", "proj" -> "org1/unknown")
response.asJson shouldEqual jsonContentOf("projects/errors/project-not-found.json", "proj" -> "org1/unknown")
}
}

Expand Down Expand Up @@ -474,7 +474,7 @@ class ProjectsRoutesSpec extends BaseRouteSpec with IOFromMap {
aclCheck.append(AclAddress.Root, Anonymous -> Set(resources.read)).accepted
Get("/v1/projects/org1/unknown/statistics") ~> routes ~> check {
status shouldEqual StatusCodes.NotFound
response.asJson shouldEqual jsonContentOf("/projects/errors/project-not-found.json", "proj" -> "org1/unknown")
response.asJson shouldEqual jsonContentOf("projects/errors/project-not-found.json", "proj" -> "org1/unknown")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RealmsRoutesSpec extends BaseRouteSpec with IOFromMap {
realmMetadata(gitlab, rev = 2, deprecated = true, createdBy = alice, updatedBy = alice)

private val githubCreated = jsonContentOf(
"/realms/realm-resource.json",
"realms/realm-resource.json",
"label" -> github.value,
"name" -> githubName.value,
"openIdConfig" -> githubOpenId,
Expand All @@ -76,7 +76,7 @@ class RealmsRoutesSpec extends BaseRouteSpec with IOFromMap {
githubUpdatedMeta.removeKeys("@context")

private val gitlabCreated = jsonContentOf(
"/realms/realm-resource.json",
"realms/realm-resource.json",
"label" -> gitlab.value,
"name" -> gitlabName.value,
"openIdConfig" -> gitlabOpenId,
Expand Down Expand Up @@ -170,7 +170,7 @@ class RealmsRoutesSpec extends BaseRouteSpec with IOFromMap {
"fail fetching a realm by id and rev when rev is invalid" in {
Get("/v1/realms/github?rev=4") ~> routes ~> check {
status shouldEqual StatusCodes.NotFound
response.asJson shouldEqual jsonContentOf("/errors/revision-not-found.json", "provided" -> 4, "current" -> 2)
response.asJson shouldEqual jsonContentOf("errors/revision-not-found.json", "provided" -> 4, "current" -> 2)
}
}

Expand Down
Loading