Skip to content

Commit

Permalink
fix plugins unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyhappydan committed Jul 27, 2023
1 parent ed53564 commit cbb8386
Show file tree
Hide file tree
Showing 15 changed files with 10 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
"description": "remoteDescription",
"algorithm": "SHA-256",
"endpoint" : "http://localhost",
"credentials" : "wqUglodAZzmNk3CEZeZgBA==",
"folder" : "myfolder",
"readPermission" : "remote/read",
"writePermission" : "remote/write",
"maxFileSize" : 52,
"@type" : "RemoteDiskStorageValue"
},
"source" : {
"credentials" : "wqUglodAZzmNk3CEZeZgBA==",
"@type" : "RemoteDiskStorage",
"name": "remoteName",
"description": "remoteDescription",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
"description": "remoteDescription",
"algorithm": "SHA-256",
"endpoint" : "http://localhost",
"credentials" : "wqUglodAZzmNk3CEZeZgBA==",
"folder" : "myfolder2",
"readPermission" : "remote/read",
"writePermission" : "remote/write",
"maxFileSize" : 42,
"@type" : "RemoteDiskStorageValue"
},
"source" : {
"credentials" : "wqUglodAZzmNk3CEZeZgBA==",
"@type" : "RemoteDiskStorage",
"name": "remoteName",
"description": "remoteDescription",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
"algorithm" : "SHA-256",
"bucket" : "mybucket",
"endpoint" : "http://localhost",
"accessKey" : "O2vOp16ah21Fk/B0OucyxQ==",
"secretKey" : "dqO3PR6kLOCFNBk9I6zsZQ==",
"readPermission" : "s3/read",
"region": "eu-west-1",
"writePermission" : "s3/write",
"maxFileSize" : 51,
"@type" : "S3StorageValue"
},
"source" : {
"secretKey" : "dqO3PR6kLOCFNBk9I6zsZQ==",
"accessKey" : "O2vOp16ah21Fk/B0OucyxQ==",
"@type" : "S3Storage",
"name": "s3name",
"description": "s3description",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
"algorithm" : "SHA-256",
"bucket" : "mybucket2",
"endpoint" : "http://localhost",
"accessKey" : "O2vOp16ah21Fk/B0OucyxQ==",
"secretKey" : "dqO3PR6kLOCFNBk9I6zsZQ==",
"readPermission" : "s3/read",
"region": "eu-west-1",
"writePermission" : "s3/write",
"maxFileSize" : 41,
"@type" : "S3StorageValue"
},
"source" : {
"secretKey" : "dqO3PR6kLOCFNBk9I6zsZQ==",
"accessKey" : "O2vOp16ah21Fk/B0OucyxQ==",
"@type" : "S3Storage",
"name": "s3name",
"description": "s3description",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"name": "remoteName",
"description": "remoteDescription",
"endpoint": "http://localhost",
"credentials": "authToken",
"folder": "myfolder",
"readPermission": "remote/read",
"writePermission": "remote/write",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"description": "s3description",
"bucket": "mybucket",
"endpoint": "http://localhost",
"accessKey": "accessKey",
"secretKey": "secretKey",
"readPermission": "s3/read",
"region": "eu-west-1",
"writePermission": "s3/write",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@type": "RemoteDiskStorage",
"name": "remoteName",
"description": "remoteDescription",
"credentials": "wqUglodAZzmNk3CEZeZgBA==",
"default": true,
"endpoint": "http://localhost",
"folder": "myfolder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@type": "RemoteDiskStorage",
"name": "remoteName",
"description": "remoteDescription",
"credentials": "wqUglodAZzmNk3CEZeZgBA==",
"default": true,
"endpoint": "http://localhost",
"folder": "myfolder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
"@type": "S3Storage",
"name": "s3name",
"description": "s3description",
"accessKey": "O2vOp16ah21Fk/B0OucyxQ==",
"bucket": "mybucket",
"default": true,
"endpoint": "http://localhost",
"maxFileSize": 51,
"readPermission": "s3/read",
"region": "eu-west-1",
"secretKey": "dqO3PR6kLOCFNBk9I6zsZQ==",
"writePermission": "s3/write"
},
"_storageId": "https://bluebrain.github.io/nexus/vocabulary/s3-storage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
"@type": "S3Storage",
"name": "s3name",
"description": "s3description",
"accessKey": "O2vOp16ah21Fk/B0OucyxQ==",
"bucket": "mybucket",
"default": true,
"endpoint": "http://localhost",
"maxFileSize": 51,
"readPermission": "s3/read",
"region": "eu-west-1",
"secretKey": "dqO3PR6kLOCFNBk9I6zsZQ==",
"writePermission": "s3/write"
},
"_storageId": "https://bluebrain.github.io/nexus/vocabulary/s3-storage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
"description": "remoteDescription",
"algorithm": "SHA-256",
"endpoint": "http://localhost",
"credentials": "wqUglodAZzmNk3CEZeZgBA==",
"folder": "myfolder",
"readPermission": "remote/read",
"writePermission": "remote/write",
"maxFileSize": 52,
"@type": "RemoteDiskStorageValue"
},
"source": {
"credentials": "wqUglodAZzmNk3CEZeZgBA==",
"@type": "RemoteDiskStorage",
"name": "remoteName",
"description": "remoteDescription",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@
"algorithm": "SHA-256",
"bucket": "mybucket",
"endpoint": "http://localhost",
"accessKey": "O2vOp16ah21Fk/B0OucyxQ==",
"secretKey": "dqO3PR6kLOCFNBk9I6zsZQ==",
"region": "eu-west-1",
"readPermission": "s3/read",
"writePermission": "s3/write",
"maxFileSize": 51,
"@type": "S3StorageValue"
},
"source": {
"secretKey": "dqO3PR6kLOCFNBk9I6zsZQ==",
"accessKey": "O2vOp16ah21Fk/B0OucyxQ==",
"@type": "S3Storage",
"name": "s3name",
"description": "s3description",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ch.epfl.bluebrain.nexus.delta.sdk.model.BaseUri
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.model.Permission
import ch.epfl.bluebrain.nexus.delta.sdk.syntax._
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Label
import ch.epfl.bluebrain.nexus.testkit.minio.MinioDocker
import ch.epfl.bluebrain.nexus.testkit.{CirceLiteral, TestHelpers}
import software.amazon.awssdk.regions.Region

Expand All @@ -27,7 +28,7 @@ trait StorageFixtures extends TestHelpers with CirceLiteral {
// format: off
implicit val config: StorageTypeConfig = StorageTypeConfig(
disk = DiskStorageConfig(diskVolume, Set(diskVolume,tmpVolume), DigestAlgorithm.default, permissions.read, permissions.write, showLocation = false, Some(5000), 50),
amazon = Some(S3StorageConfig(DigestAlgorithm.default, Some("localhost"), Some(Secret("accessKey")), Some(Secret("secretKey")), permissions.read, permissions.write, showLocation = false, 60)),
amazon = Some(S3StorageConfig(DigestAlgorithm.default, Some("localhost"), Some(Secret(MinioDocker.RootUser)), Some(Secret(MinioDocker.RootPassword)), permissions.read, permissions.write, showLocation = false, 60)),
remoteDisk = Some(RemoteDiskStorageConfig(DigestAlgorithm.default, BaseUri("http://localhost", Label.unsafe("v1")), None, permissions.read, permissions.write, showLocation = false, 70, RetryStrategyConfig.AlwaysGiveUp)),
)
val diskFields = DiskStorageFields(Some("diskName"), Some("diskDescription"), default = true, Some(tmpVolume), Some(Permission.unsafe("disk/read")), Some(Permission.unsafe("disk/write")), Some(1000), Some(50))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ class StorageSerializationSuite extends SerializationSuite with StorageFixtures
private val storageEventMetricEncoder = StorageEvent.storageEventMetricEncoder

storagesMapping.foreach { case (event, (database, sse), action) =>
test(s"Correctly serialize ${event.getClass.getName}") {
test(s"Correctly serialize ${event.getClass.getSimpleName} for ${event.tpe}") {
assertEquals(storageEventSerializer.codec(event), database)
}

test(s"Correctly deserialize ${event.getClass.getName}") {
test(s"Correctly deserialize ${event.getClass.getSimpleName} for ${event.tpe}") {
assertEquals(storageEventSerializer.codec.decodeJson(database), Right(event))
}

test(s"Correctly serialize ${event.getClass.getName} as an SSE") {
test(s"Correctly serialize ${event.getClass.getSimpleName} for ${event.tpe} as an SSE") {
storageSseEncoder.toSse
.decodeJson(database)
.assertRight(SseData(ClassUtils.simpleName(event), Some(projectRef), sse))
}

test(s"Correctly encode ${event.getClass.getName} to metric") {
test(s"Correctly encode ${event.getClass.getSimpleName} for ${event.tpe} to metric") {
storageEventMetricEncoder.toMetric.decodeJson(database).assertRight {
ProjectScopedMetric(
instant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.DigestAlgori
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.Storage.S3Storage
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageValue.S3StorageValue
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.AkkaSourceHelpers
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.StorageFileRejection.FetchFileRejection.{FileNotFound, UnexpectedFetchError}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.StorageFileRejection.SaveFileRejection.{ResourceAlreadyExists, UnexpectedSaveError}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.StorageFileRejection.FetchFileRejection.FileNotFound
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.StorageFileRejection.SaveFileRejection.ResourceAlreadyExists
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.s3.MinioSpec._
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.permissions.{read, write}
import ch.epfl.bluebrain.nexus.delta.sdk.model.Tags
Expand All @@ -24,13 +24,14 @@ import ch.epfl.bluebrain.nexus.testkit.minio.MinioDocker
import ch.epfl.bluebrain.nexus.testkit.minio.MinioDocker._
import io.circe.Json
import monix.execution.Scheduler
import org.scalatest.BeforeAndAfterAll
import org.scalatest.{BeforeAndAfterAll, DoNotDiscover}
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import software.amazon.awssdk.regions.Region

import java.util.UUID

@DoNotDiscover
class S3StorageSaveAndFetchFileSpec(docker: MinioDocker)
extends TestKit(ActorSystem("S3StorageSaveAndFetchFileSpec"))
with AnyWordSpecLike
Expand Down Expand Up @@ -88,11 +89,6 @@ class S3StorageSaveAndFetchFileSpec(docker: MinioDocker)
val content = "file content"
val entity = HttpEntity(content)

"fail saving a file to a bucket on wrong credentials" in {
val description = FileDescription(uuid, filename, Some(`text/plain(UTF-8)`))
storage.saveFile.apply(description, entity).rejectedWith[UnexpectedSaveError]
}

"save a file to a bucket" in {
val description = FileDescription(uuid, filename, Some(`text/plain(UTF-8)`))
storage.saveFile.apply(description, entity).accepted shouldEqual attributes
Expand All @@ -103,10 +99,6 @@ class S3StorageSaveAndFetchFileSpec(docker: MinioDocker)
consume(sourceFetched) shouldEqual content
}

"fail fetching a file to a bucket on wrong credentials" in {
storage.fetchFile.apply(attributes).rejectedWith[UnexpectedFetchError]
}

"fail fetching a file that does not exist" in {
storage.fetchFile.apply(attributes.copy(path = Uri.Path("other.txt"))).rejectedWith[FileNotFound]
}
Expand Down

0 comments on commit cbb8386

Please sign in to comment.