From 36639b65a96d80ad80a56cc895b8ade8e5613576 Mon Sep 17 00:00:00 2001 From: Bala FA Date: Mon, 24 Oct 2016 13:56:13 -0700 Subject: [PATCH] rename completeMultipartMD5() into getCompleteMultipartMD5(). (#3051) --- cmd/fs-v1-multipart.go | 2 +- cmd/object-api-multipart_test.go | 2 +- cmd/object-handlers_test.go | 2 +- cmd/object-utils.go | 2 +- cmd/object-utils_test.go | 32 ++++++++++++++++++++++++++++++++ cmd/xl-v1-multipart.go | 2 +- 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/cmd/fs-v1-multipart.go b/cmd/fs-v1-multipart.go index d583f579f..036ebe40f 100644 --- a/cmd/fs-v1-multipart.go +++ b/cmd/fs-v1-multipart.go @@ -643,7 +643,7 @@ func (fs fsObjects) CompleteMultipartUpload(bucket string, object string, upload defer nsMutex.Unlock(minioMetaBucket, fsAppendMetaPath, opsID) // Calculate s3 compatible md5sum for complete multipart. - s3MD5, err := completeMultipartMD5(parts...) + s3MD5, err := getCompleteMultipartMD5(parts...) if err != nil { return "", err } diff --git a/cmd/object-api-multipart_test.go b/cmd/object-api-multipart_test.go index 246f41087..29edf7a6d 100644 --- a/cmd/object-api-multipart_test.go +++ b/cmd/object-api-multipart_test.go @@ -1864,7 +1864,7 @@ func testObjectCompleteMultipartUpload(obj ObjectLayer, instanceType string, t T }, }, } - s3MD5, err := completeMultipartMD5(inputParts[3].parts...) + s3MD5, err := getCompleteMultipartMD5(inputParts[3].parts...) if err != nil { t.Fatalf("Obtaining S3MD5 failed") } diff --git a/cmd/object-handlers_test.go b/cmd/object-handlers_test.go index 2162f7748..a7ab5464a 100644 --- a/cmd/object-handlers_test.go +++ b/cmd/object-handlers_test.go @@ -1245,7 +1245,7 @@ func testAPICompleteMultipartHandler(obj ObjectLayer, instanceType, bucketName s } // on successfull complete multipart operation the s3MD5 for the parts uploaded will be returned. - s3MD5, err := completeMultipartMD5(inputParts[3].parts...) + s3MD5, err := getCompleteMultipartMD5(inputParts[3].parts...) if err != nil { t.Fatalf("Obtaining S3MD5 failed") } diff --git a/cmd/object-utils.go b/cmd/object-utils.go index f35f86c11..85aec3474 100644 --- a/cmd/object-utils.go +++ b/cmd/object-utils.go @@ -141,7 +141,7 @@ func getUUID() (uuidStr string) { } // Create an s3 compatible MD5sum for complete multipart transaction. -func completeMultipartMD5(parts ...completePart) (string, error) { +func getCompleteMultipartMD5(parts ...completePart) (string, error) { var finalMD5Bytes []byte for _, part := range parts { md5Bytes, err := hex.DecodeString(part.ETag) diff --git a/cmd/object-utils_test.go b/cmd/object-utils_test.go index 0138df35e..b57d0960e 100644 --- a/cmd/object-utils_test.go +++ b/cmd/object-utils_test.go @@ -136,3 +136,35 @@ func TestLimitReader(t *testing.T) { } } } + +// Tests getCompleteMultipartMD5 +func TestGetCompleteMultipartMD5(t *testing.T) { + testCases := []struct { + parts []completePart + expectedResult string + expectedErr string + }{ + // Wrong MD5 hash string + {[]completePart{{ETag: "wrong-md5-hash-string"}}, "", "encoding/hex: odd length hex string"}, + + // Single completePart with valid MD5 hash string. + {[]completePart{{ETag: "cf1f738a5924e645913c984e0fe3d708"}}, "10dc1617fbcf0bd0858048cb96e6bd77-1", ""}, + + // Multiple completePart with valid MD5 hash string. + {[]completePart{{ETag: "cf1f738a5924e645913c984e0fe3d708"}, {ETag: "9ccbc9a80eee7fb6fdd22441db2aedbd"}}, "0239a86b5266bb624f0ac60ba2aed6c8-2", ""}, + } + + for i, test := range testCases { + result, err := getCompleteMultipartMD5(test.parts...) + if result != test.expectedResult { + t.Fatalf("test %d failed: expected: result=%v, got=%v", i+1, test.expectedResult, result) + } + errString := "" + if err != nil { + errString = err.Error() + } + if errString != test.expectedErr { + t.Fatalf("test %d failed: expected: err=%v, got=%v", i+1, test.expectedErr, err) + } + } +} diff --git a/cmd/xl-v1-multipart.go b/cmd/xl-v1-multipart.go index 43e5e2cdc..9b705e3f2 100644 --- a/cmd/xl-v1-multipart.go +++ b/cmd/xl-v1-multipart.go @@ -649,7 +649,7 @@ func (xl xlObjects) CompleteMultipartUpload(bucket string, object string, upload return "", traceError(InvalidUploadID{UploadID: uploadID}) } // Calculate s3 compatible md5sum for complete multipart. - s3MD5, err := completeMultipartMD5(parts...) + s3MD5, err := getCompleteMultipartMD5(parts...) if err != nil { return "", err }