github.com/minio/minio-go/v6@v6.0.57/api-compose-object_test.go (about) 1 /* 2 * MinIO Go Library for Amazon S3 Compatible Cloud Storage 3 * Copyright 2017 MinIO, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package minio 18 19 import ( 20 "reflect" 21 "strings" 22 "testing" 23 ) 24 25 const ( 26 gb1 = 1024 * 1024 * 1024 27 gb5 = 5 * gb1 28 gb5p1 = gb5 + 1 29 gb10p1 = 2*gb5 + 1 30 gb10p2 = 2*gb5 + 2 31 ) 32 33 func TestPartsRequired(t *testing.T) { 34 testCases := []struct { 35 size, ref int64 36 }{ 37 {0, 0}, 38 {1, 1}, 39 {gb5, 10}, 40 {gb5p1, 10}, 41 {2 * gb5, 20}, 42 {gb10p1, 20}, 43 {gb10p2, 20}, 44 {gb10p1 + gb10p2, 40}, 45 {maxMultipartPutObjectSize, 10000}, 46 } 47 48 for i, testCase := range testCases { 49 res := partsRequired(testCase.size) 50 if res != testCase.ref { 51 t.Errorf("Test %d - output did not match with reference results, Expected %d, got %d", i+1, testCase.ref, res) 52 } 53 } 54 } 55 56 func TestCalculateEvenSplits(t *testing.T) { 57 58 testCases := []struct { 59 // input size and source object 60 size int64 61 src SourceInfo 62 63 // output part-indexes 64 starts, ends []int64 65 }{ 66 {0, SourceInfo{start: -1}, nil, nil}, 67 {1, SourceInfo{start: -1}, []int64{0}, []int64{0}}, 68 {1, SourceInfo{start: 0}, []int64{0}, []int64{0}}, 69 70 {gb1, SourceInfo{start: -1}, []int64{0, 536870912}, []int64{536870911, 1073741823}}, 71 {gb5, SourceInfo{start: -1}, 72 []int64{0, 536870912, 1073741824, 1610612736, 2147483648, 2684354560, 73 3221225472, 3758096384, 4294967296, 4831838208}, 74 []int64{536870911, 1073741823, 1610612735, 2147483647, 2684354559, 3221225471, 75 3758096383, 4294967295, 4831838207, 5368709119}, 76 }, 77 78 // 2 part splits 79 {gb5p1, SourceInfo{start: -1}, 80 []int64{0, 536870913, 1073741825, 1610612737, 2147483649, 2684354561, 81 3221225473, 3758096385, 4294967297, 4831838209}, 82 []int64{536870912, 1073741824, 1610612736, 2147483648, 2684354560, 3221225472, 83 3758096384, 4294967296, 4831838208, 5368709120}, 84 }, 85 {gb5p1, SourceInfo{start: -1}, 86 []int64{0, 536870913, 1073741825, 1610612737, 2147483649, 2684354561, 87 3221225473, 3758096385, 4294967297, 4831838209}, 88 []int64{536870912, 1073741824, 1610612736, 2147483648, 2684354560, 3221225472, 89 3758096384, 4294967296, 4831838208, 5368709120}, 90 }, 91 92 // 3 part splits 93 {gb10p1, SourceInfo{start: -1}, 94 []int64{0, 536870913, 1073741825, 1610612737, 2147483649, 2684354561, 95 3221225473, 3758096385, 4294967297, 4831838209, 5368709121, 96 5905580033, 6442450945, 6979321857, 7516192769, 8053063681, 97 8589934593, 9126805505, 9663676417, 10200547329}, 98 []int64{536870912, 1073741824, 1610612736, 2147483648, 2684354560, 99 3221225472, 3758096384, 4294967296, 4831838208, 5368709120, 100 5905580032, 6442450944, 6979321856, 7516192768, 8053063680, 101 8589934592, 9126805504, 9663676416, 10200547328, 10737418240}, 102 }, 103 {gb10p2, SourceInfo{start: -1}, 104 []int64{0, 536870913, 1073741826, 1610612738, 2147483650, 2684354562, 105 3221225474, 3758096386, 4294967298, 4831838210, 5368709122, 106 5905580034, 6442450946, 6979321858, 7516192770, 8053063682, 107 8589934594, 9126805506, 9663676418, 10200547330}, 108 []int64{536870912, 1073741825, 1610612737, 2147483649, 2684354561, 109 3221225473, 3758096385, 4294967297, 4831838209, 5368709121, 110 5905580033, 6442450945, 6979321857, 7516192769, 8053063681, 111 8589934593, 9126805505, 9663676417, 10200547329, 10737418241}, 112 }, 113 } 114 115 for i, testCase := range testCases { 116 resStart, resEnd := calculateEvenSplits(testCase.size, testCase.src) 117 if !reflect.DeepEqual(testCase.starts, resStart) || !reflect.DeepEqual(testCase.ends, resEnd) { 118 t.Errorf("Test %d - output did not match with reference results, Expected %d/%d, got %d/%d", i+1, testCase.starts, testCase.ends, resStart, resEnd) 119 } 120 } 121 } 122 123 func TestGetUserMetaHeadersMap(t *testing.T) { 124 125 userMetadata := map[string]string{ 126 "test": "test", 127 "x-amz-acl": "public-read-write", 128 "content-type": "application/binary", 129 "X-Amz-Storage-Class": "rrs", 130 "x-amz-grant-write": "test@exo.ch", 131 } 132 133 destInfo, _ := NewDestinationInfo("bucket", "object", nil, userMetadata) 134 135 r := destInfo.getUserMetaHeadersMap(true) 136 137 i := 0 138 139 if _, ok := r["x-amz-metadata-directive"]; !ok { 140 t.Errorf("Test %d - metadata directive was expected but is missing", i) 141 i++ 142 } 143 144 for k := range r { 145 if strings.HasSuffix(k, "test") && !strings.HasPrefix(k, "x-amz-meta-") { 146 t.Errorf("Test %d - meta %q was expected as an x amz meta", i, k) 147 i++ 148 } 149 150 if !strings.HasSuffix(k, "test") && strings.HasPrefix(k, "x-amz-meta-") { 151 t.Errorf("Test %d - an amz/standard/storageClass Header was expected but got an x amz meta data", i) 152 i++ 153 } 154 } 155 }