Skip to content

Commit

Permalink
Update localStackS3Client usage
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergrabinski committed Apr 12, 2024
1 parent c2682d2 commit d08a97a
Showing 1 changed file with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package ch.epfl.bluebrain.nexus.ship
import cats.effect.IO
import cats.syntax.all._
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.s3.LocalStackS3StorageClient
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.s3.client.S3StorageClient
import ch.epfl.bluebrain.nexus.ship.RunShipSuite.{clearDB, expectedImportReport}
import ch.epfl.bluebrain.nexus.ship.S3RunShipSuite.uploadFileToS3
import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite
import eu.timepit.refined.types.string.NonEmptyString
import fs2.aws.s3.models.Models.BucketName
import fs2.io.file.Path
import io.laserdisc.pure.s3.tagless.S3AsyncClientOp
import munit.AnyFixture
import org.scalatest.time.SpanSugar.convertIntToGrainOfTime
import software.amazon.awssdk.services.s3.model.{CreateBucketRequest, PutObjectRequest, PutObjectResponse}
Expand All @@ -21,9 +21,9 @@ class S3RunShipSuite extends NexusSuite with RunShipSuite.Fixture with LocalStac

override def munitIOTimeout: Duration = 60.seconds

override def munitFixtures: Seq[AnyFixture[_]] = List(mainFixture, localStackS3Client)
private lazy val xas = mainFixture()
private lazy val (s3Client: S3StorageClient, _) = localStackS3Client()
override def munitFixtures: Seq[AnyFixture[_]] = List(mainFixture, localStackS3Client)
private lazy val xas = mainFixture()
private lazy val (s3Client, fs2S3client, _) = localStackS3Client()

private val bucket = BucketName(NonEmptyString.unsafeFrom("bucket"))

Expand All @@ -36,15 +36,15 @@ class S3RunShipSuite extends NexusSuite with RunShipSuite.Fixture with LocalStac
test("Run import from S3 providing a single file") {
val importFilePath = Path("/import/import.json")
for {
_ <- uploadFileToS3(s3Client, bucket, importFilePath)
_ <- uploadFileToS3(fs2S3client, bucket, importFilePath)
_ <- RunShip.s3Ship(s3Client, bucket).run(importFilePath, None).assertEquals(expectedImportReport)
} yield ()
}

test("Succeed in overloading the default config with an external config in S3") {
val configPath = Path("/config/external.conf")
for {
_ <- uploadFileToS3(s3Client, bucket, configPath)
_ <- uploadFileToS3(fs2S3client, bucket, configPath)
shipConfig <- RunShip.s3Ship(s3Client, bucket).loadConfig(configPath.some)
_ = assertEquals(shipConfig.baseUri.toString, "https://bbp.epfl.ch/v1")
} yield ()
Expand All @@ -53,10 +53,9 @@ class S3RunShipSuite extends NexusSuite with RunShipSuite.Fixture with LocalStac
test("Run import from S3 providing a directory") {
val directoryPath = Path("/import/multi-part-import")
for {
_ <- uploadFileToS3(s3Client, bucket, Path("/import/multi-part-import/2024-04-05T14:38:31.165389Z.json"))
_ <-
uploadFileToS3(s3Client, bucket, Path("/import/multi-part-import/2024-04-05T14:38:31.165389Z.success"))
_ <- uploadFileToS3(s3Client, bucket, Path("/import/multi-part-import/2024-04-06T11:34:31.165389Z.json"))
_ <- uploadFileToS3(fs2S3client, bucket, Path("/import/multi-part-import/2024-04-05T14:38:31.165389Z.json"))
_ <- uploadFileToS3(fs2S3client, bucket, Path("/import/multi-part-import/2024-04-05T14:38:31.165389Z.success"))
_ <- uploadFileToS3(fs2S3client, bucket, Path("/import/multi-part-import/2024-04-06T11:34:31.165389Z.json"))
_ <- RunShip
.s3Ship(s3Client, bucket)
.run(directoryPath, None)
Expand All @@ -68,13 +67,12 @@ class S3RunShipSuite extends NexusSuite with RunShipSuite.Fixture with LocalStac

object S3RunShipSuite {

def uploadFileToS3(s3Client: S3StorageClient, bucket: BucketName, path: Path): IO[PutObjectResponse] = {
s3Client.underlyingClient.createBucket(CreateBucketRequest.builder().bucket(bucket.value.value).build) >>
s3Client.underlyingClient
.putObject(
PutObjectRequest.builder.bucket(bucket.value.value).key(path.toString).build,
Paths.get(getClass.getResource(path.toString).toURI)
)
def uploadFileToS3(s3Client: S3AsyncClientOp[IO], bucket: BucketName, path: Path): IO[PutObjectResponse] = {
s3Client.createBucket(CreateBucketRequest.builder().bucket(bucket.value.value).build) >>
s3Client.putObject(
PutObjectRequest.builder.bucket(bucket.value.value).key(path.toString).build,
Paths.get(getClass.getResource(path.toString).toURI)
)
}

}

0 comments on commit d08a97a

Please sign in to comment.