Use humanize constants for KiB, MiB and GiB units. (#3322)

This commit is contained in:
Bala FA
2016-11-22 18:18:22 -08:00
committed by Harshavardhana
parent c1ebcbcda2
commit 825000bc34
23 changed files with 170 additions and 135 deletions

View File

@@ -28,6 +28,8 @@ import (
"strconv"
"sync"
"testing"
humanize "github.com/dustin/go-humanize"
)
// Type to capture different modifications to API request to simulate failure cases.
@@ -58,7 +60,7 @@ func testAPIHeadObjectHandler(obj ObjectLayer, instanceType, bucketName string,
bytesData := []struct {
byteData []byte
}{
{generateBytesData(6 * 1024 * 1024)},
{generateBytesData(6 * humanize.MiByte)},
}
// set of inputs for uploading the objects before tests for downloading is done.
putObjectInputs := []struct {
@@ -205,7 +207,7 @@ func testAPIGetObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
bytesData := []struct {
byteData []byte
}{
{generateBytesData(6 * 1024 * 1024)},
{generateBytesData(6 * humanize.MiByte)},
}
// set of inputs for uploading the objects before tests for downloading is done.
putObjectInputs := []struct {
@@ -421,9 +423,9 @@ func testAPIPutObjectStreamSigV4Handler(obj ObjectLayer, instanceType, bucketNam
credentials credential, t *testing.T) {
objectName := "test-object"
bytesDataLen := 65 * 1024
bytesDataLen := 65 * humanize.KiByte
bytesData := bytes.Repeat([]byte{'a'}, bytesDataLen)
oneKData := bytes.Repeat([]byte("a"), 1024)
oneKData := bytes.Repeat([]byte("a"), 1*humanize.KiByte)
err := initEventNotifier(obj)
if err != nil {
@@ -465,7 +467,7 @@ func testAPIPutObjectStreamSigV4Handler(obj ObjectLayer, instanceType, bucketNam
objectName: objectName,
data: bytesData,
dataLen: len(bytesData),
chunkSize: 64 * 1024, // 64k
chunkSize: 64 * humanize.KiByte,
expectedContent: []byte{},
expectedRespStatus: http.StatusOK,
accessKey: credentials.AccessKeyID,
@@ -479,7 +481,7 @@ func testAPIPutObjectStreamSigV4Handler(obj ObjectLayer, instanceType, bucketNam
objectName: objectName,
data: bytesData,
dataLen: len(bytesData),
chunkSize: 1 * 1024, // 1k
chunkSize: 1 * humanize.KiByte,
expectedContent: []byte{},
expectedRespStatus: http.StatusOK,
accessKey: credentials.AccessKeyID,
@@ -493,7 +495,7 @@ func testAPIPutObjectStreamSigV4Handler(obj ObjectLayer, instanceType, bucketNam
objectName: objectName,
data: bytesData,
dataLen: len(bytesData),
chunkSize: 64 * 1024, // 64k
chunkSize: 64 * humanize.KiByte,
expectedContent: []byte{},
expectedRespStatus: http.StatusForbidden,
accessKey: "",
@@ -507,7 +509,7 @@ func testAPIPutObjectStreamSigV4Handler(obj ObjectLayer, instanceType, bucketNam
objectName: objectName,
data: bytesData,
dataLen: len(bytesData),
chunkSize: 64 * 1024, // 64k
chunkSize: 64 * humanize.KiByte,
expectedContent: []byte{},
expectedRespStatus: http.StatusBadRequest,
accessKey: credentials.AccessKeyID,
@@ -522,7 +524,7 @@ func testAPIPutObjectStreamSigV4Handler(obj ObjectLayer, instanceType, bucketNam
objectName: objectName,
data: bytesData,
dataLen: len(bytesData),
chunkSize: 100 * 1024, // 100k
chunkSize: 100 * humanize.KiByte,
expectedContent: []byte{},
expectedRespStatus: http.StatusOK,
accessKey: credentials.AccessKeyID,
@@ -696,7 +698,7 @@ func testAPIPutObjectHandler(obj ObjectLayer, instanceType, bucketName string, a
}
objectName := "test-object"
// byte data for PutObject.
bytesData := generateBytesData(6 * 1024 * 1024)
bytesData := generateBytesData(6 * humanize.KiByte)
copySourceHeader := http.Header{}
copySourceHeader.Set("X-Amz-Copy-Source", "somewhere")
@@ -940,7 +942,7 @@ func testAPICopyObjectHandler(obj ObjectLayer, instanceType, bucketName string,
bytesData := []struct {
byteData []byte
}{
{generateBytesData(6 * 1024 * 1024)},
{generateBytesData(6 * humanize.KiByte)},
}
buffers := []*bytes.Buffer{
@@ -1404,7 +1406,7 @@ func testAPICompleteMultipartHandler(obj ObjectLayer, instanceType, bucketName s
// Parts with size greater than 5 MB.
// Generating a 6MB byte array.
validPart := bytes.Repeat([]byte("abcdef"), 1024*1024)
validPart := bytes.Repeat([]byte("abcdef"), 1*humanize.MiByte)
validPartMD5 := getMD5Hash(validPart)
// Create multipart parts.
// Need parts to be uploaded before CompleteMultiPartUpload can be called tested.
@@ -1759,7 +1761,7 @@ func testAPIAbortMultipartHandler(obj ObjectLayer, instanceType, bucketName stri
// Parts with size greater than 5 MB.
// Generating a 6MB byte array.
validPart := bytes.Repeat([]byte("abcdef"), 1024*1024)
validPart := bytes.Repeat([]byte("abcdef"), 1*humanize.MiByte)
validPartMD5 := getMD5Hash(validPart)
// Create multipart parts.
// Need parts to be uploaded before AbortMultiPartUpload can be called tested.
@@ -1914,7 +1916,7 @@ func testAPIDeleteObjectHandler(obj ObjectLayer, instanceType, bucketName string
bytesData := []struct {
byteData []byte
}{
{generateBytesData(6 * 1024 * 1024)},
{generateBytesData(6 * humanize.MiByte)},
}
// set of inputs for uploading the objects before tests for deleting them is done.