diff --git a/src/main/scala/zio/s3/Test.scala b/src/main/scala/zio/s3/Test.scala index 2b9830aa..c79d89d0 100644 --- a/src/main/scala/zio/s3/Test.scala +++ b/src/main/scala/zio/s3/Test.scala @@ -16,8 +16,8 @@ package zio.s3 -import java.io.FileInputStream -import java.nio.file.StandardOpenOption +import java.io.{ FileInputStream, FileNotFoundException } +import java.nio.file.{ NoSuchFileException, StandardOpenOption } import java.nio.file.attribute.BasicFileAttributes import java.util.UUID import java.util.concurrent.CompletableFuture @@ -30,14 +30,12 @@ import zio.nio.file.Files import zio.s3.S3Bucket._ import zio.stream.{ Stream, ZStream } -import java.io.FileNotFoundException - /** * Stub Service which is back by a filesystem storage */ object Test { - private def fileNotFound(err: FileNotFoundException): S3Exception = + private def fileNotFound(err: Throwable): S3Exception = S3Exception .builder() .message("Key does not exist.") @@ -81,7 +79,7 @@ object Test { .scoped(ZIO.fromAutoCloseable(ZIO.attempt(new FileInputStream((path / bucketName / key).toFile)))) .flatMap(ZStream.fromInputStream(_, 2048)) .refineOrDie { - case e: FileNotFoundException => fileNotFound(e) + case e @ (_: FileNotFoundException | _: NoSuchFileException) => fileNotFound(e) } override def getObjectMetadata(bucketName: String, key: String): IO[S3Exception, ObjectMetadata] = @@ -91,7 +89,10 @@ object Test { file <- Files .readAttributes[BasicFileAttributes](path / bucketName / key) .map(p => ObjectMetadata(metadata, contentType, p.size())) - } yield file).orDie + } yield file) + .refineOrDie { + case e @ (_: FileNotFoundException | _: NoSuchFileException) => fileNotFound(e) + } override def listObjects( bucketName: String, diff --git a/src/test/scala/zio/s3/S3Test.scala b/src/test/scala/zio/s3/S3Test.scala index e82a47d4..776be7e0 100644 --- a/src/test/scala/zio/s3/S3Test.scala +++ b/src/test/scala/zio/s3/S3Test.scala @@ -191,6 +191,13 @@ object S3Suite { .fold(ex => ex.statusCode() == 404, _ => false) } yield assertTrue(succeed) }, + test("get object metadata - invalid identifier") { + for { + succeed <- getObjectMetadata(bucketName, UUID.randomUUID().toString) + .refineToOrDie[S3Exception] + .fold(ex => ex.statusCode() == 404, _ => false) + } yield assertTrue(succeed) + }, test("get nextObjects") { for { token <- listObjects(bucketName, ListObjectOptions.fromMaxKeys(1)).map(_.nextContinuationToken)