Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergrabinski committed Apr 3, 2024
1 parent ec56f7e commit e356d2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions ship/src/test/resources/config/project-mapping.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ship {
project-mapping = {
"public/sscx": "obp/somato"
"private/mmb": "obp/reference",
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.model.EntityType
import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset
import ch.epfl.bluebrain.nexus.delta.sourcing.postgres.Doobie.{transactors, PostgresPassword, PostgresUser}
import ch.epfl.bluebrain.nexus.ship.ImportReport.Count
import ch.epfl.bluebrain.nexus.ship.RunShipSuite.clearDB
import ch.epfl.bluebrain.nexus.ship.RunShipSuite.{check, clearDB}
import ch.epfl.bluebrain.nexus.testkit.config.SystemPropertyOverride
import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite
import ch.epfl.bluebrain.nexus.testkit.postgres.PostgresContainer
Expand Down Expand Up @@ -61,6 +61,18 @@ class RunShipSuite extends NexusSuite with RunShipSuite.Fixture {
} yield ()
}

test("Import with project mapping") {
for {
externalConfigPath <- loader.absolutePath("config/project-mapping.conf").map(x => Some(Path(x)))
importFileWithTwoProjects <- asPath("import/import.json")
_ <- new RunShip().run(importFileWithTwoProjects, externalConfigPath, Offset.start)
_ <- check(xas).map { projects =>
assert(projects.size == 1)
assert(projects.contains(("obp", "somato")))
}
} yield ()
}

private def asPath(path: String): IO[Path] = {
ClasspathResourceLoader().absolutePath(path).map(Path(_))
}
Expand All @@ -77,14 +89,20 @@ object RunShipSuite {
| DELETE FROM scoped_events; DELETE FROM scoped_states;
|""".stripMargin.update.run.void.transact(xas.write)

def check(xas: Transactors) =
sql"""
| SELECT DISTINCT org, project FROM scoped_events;
""".stripMargin.query[(String, String)].to[List].transact(xas.read)

trait Fixture { self: CatsEffectSuite =>

private def initConfig(postgres: PostgresContainer) =
Map(
"ship.database.access.host" -> postgres.getHost,
"ship.database.access.port" -> postgres.getMappedPort(5432).toString,
"ship.database.tables-autocreate" -> "true",
"ship.organizations.values.public" -> "The public organization"
"ship.organizations.values.public" -> "The public organization",
"ship.organizations.values.obp" -> "The OBP organization"
)

private val resource: Resource[IO, Transactors] = transactors(
Expand Down

0 comments on commit e356d2d

Please sign in to comment.