findify / s3mock

Embedded S3 server for easy mocking
MIT License
387 stars 107 forks source link

Support metadata for multipart upload #100

Closed chetanmeh closed 6 years ago

chetanmeh commented 6 years ago

Currently the metadata is only stored with putObject and not stored when passed with multipart upload.

Issue can be seen with below patch

Index: src/test/scala/io/findify/s3mock/MultipartUploadTest.scala
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/test/scala/io/findify/s3mock/MultipartUploadTest.scala  (date 1521624607000)
+++ src/test/scala/io/findify/s3mock/MultipartUploadTest.scala  (date 1521625126000)
@@ -84,5 +84,23 @@
       exc.getStatusCode shouldBe 404
       exc.getErrorCode shouldBe "NoSuchBucket"
     }
+
+    it should "upload multipart with metadata" in {
+      s3.createBucket("getput")
+      val metadata: ObjectMetadata = new ObjectMetadata()
+      metadata.setContentType("application/json")
+      metadata.addUserMetadata("metamaic", "maic")
+      val init = s3.initiateMultipartUpload(new InitiateMultipartUploadRequest("getput", "foo4", metadata))
+      val p1 = s3.uploadPart(new UploadPartRequest().withBucketName("getput").withPartSize(10).withKey("foo4").withPartNumber(1).withUploadId(init.getUploadId).withInputStream(new ByteArrayInputStream("hellohello".getBytes())))
+      val p2 = s3.uploadPart(new UploadPartRequest().withBucketName("getput").withPartSize(10).withKey("foo4").withPartNumber(2).withUploadId(init.getUploadId).withInputStream(new ByteArrayInputStream("worldworld".getBytes())))
+      val result = s3.completeMultipartUpload(new CompleteMultipartUploadRequest("getput", "foo4", init.getUploadId, List(p1.getPartETag, p2.getPartETag).asJava))
+      result.getKey shouldBe "foo4"
+      val s3Object = s3.getObject("getput", "foo4")
+      getContent(s3Object) shouldBe "hellohelloworldworld"
+
+      val actualMetadata: ObjectMetadata = s3Object.getObjectMetadata
+      actualMetadata.getContentType shouldBe "application/json"
+      actualMetadata.getUserMetadata.get("metamaic") shouldBe "maic"
+    }
   }
 }
drobert commented 5 years ago

Is there any chance of cutting a new release with this fix soon? I'm just now trying out S3Mock and it's working for all of our tests except for a select few that rely on custom headers during multipart uploads. Seems like this feature is ready to go.